### Creating a Simple Anchor (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Example of creating a basic anchor element with just a string as content and no additional metadata.
```javascript
["anchor", "plain anchor"]
```
--------------------------------
### Example JSON Document Metadata
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Illustrates the structure and available optional fields for the metadata object, which is the first element in the JSON array representing the PDF document.
```JSON
{"right-margin":10,
"subject":"Some subject",
"creator":"Jane Doe",
"doc-header":["inspired by", "William Shakespeare"],
"bottom-margin":25,
"pages":true,
"author":"John Doe",
"header":"Page header text appears on each page",
"left-margin":10,
"title":"Test doc",
"size":"a4",
"letterhead":["A simple Letter head"],
"orientation":"landscape",
"font":{"size":11},
"footer":
"Page footer text appears on each page (includes page number)",
"top-margin":20}
```
--------------------------------
### Example JSON Font Configuration
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Shows how to define font properties like family, size, style, and color using a JSON object within the 'font' field of the document metadata.
```JSON
{"style":"bold", "size":18, "family":"helvetica", "color":[0, 234, 123]}
```
--------------------------------
### Creating a Superscript Chunk (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Example of creating a text chunk that will be rendered as superscript using the 'super' metadata flag.
```javascript
["chunk", {"super":true}, "5"]
```
--------------------------------
### Creating a Subscript Chunk (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Example of creating a text chunk that will be rendered as subscript using the 'sub' metadata flag.
```javascript
["chunk", {"sub":true}, "2"]
```
--------------------------------
### Defining Tables in JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Provides various examples of defining tables using the 'table' tag, showcasing different metadata options such as headers, width, borders, cell borders, spacing, padding, column widths, and header styling.
```javascript
["table",
{"header":["Row 1", "Row 2", "Row 3"],
"width":50,
"border":false,
"cell-border":false},
[["cell", {"colspan":2}, "Foo"], "Bar"], ["foo1", "bar1", "baz1"],
["foo2", "bar2", "baz2"]]
```
```javascript
["table", {"border-width":10, "header":["Row 1", "Row 2", "Row 3"]},
["foo", "bar", "baz"], ["foo1", "bar1", "baz1"],
["foo2", "bar2", "baz2"]]
```
```javascript
["table",
{"border":false,
"widths":[2, 1, 1],
"header":[{"color":[100, 100, 100]}, "Singe Header"]},
["foo", "bar", "baz"], ["foo1", "bar1", "baz1"],
["foo2", "bar2", "baz2"]]
```
```javascript
["table",
{"cell-border":false,
"header":[{"color":[100, 100, 100]}, "Row 1", "Row 2", "Row 3"],
"cellSpacing":20,
"header-color":[100, 100, 100]},
["foo",
["cell",
["phrase",
{"style":"italic",
"size":18,
"family":"halvetica",
"color":[200, 55, 221]},
"Hello Clojure!"]],
"baz"],
["foo1", ["cell", {"color":[100, 10, 200]}, "bar1"], "baz1"],
["foo2", "bar2", "baz2"]]
```
--------------------------------
### Complete PDF Document Structure Example (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This snippet shows a comprehensive data structure, represented as a JavaScript array of objects and arrays, that defines the layout, metadata, and content elements (headings, paragraphs, tables, lists, charts, etc.) for generating a PDF document. This structure is intended to be processed by a PDF generation library.
```javascript
[{"right-margin":50,
"subject":"Some subject",
"creator":"Jane Doe",
"doc-header":["inspired by", "William Shakespeare"],
"bottom-margin":25,
"author":"John Doe",
"header":"page header",
"left-margin":10,
"title":"Test doc",
"size":"a4",
"footer":"page",
"top-margin":20},
["heading", "Lorem Ipsum"],
["paragraph", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec non iaculis lectus. Integer vel libero libero. Phasellus metus augue, consequat a viverra vel, fermentum convallis sem. Etiam venenatis laoreet quam, et adipiscing mi lobortis sit amet. Fusce eu velit vitae dolor vulputate imperdiet. Suspendisse dui risus, mollis ut tempor sed, dapibus a leo. Aenean nisi augue, placerat a cursus eu, convallis viverra urna. Nunc iaculis pharetra pretium. Suspendisse sit amet erat nisl, quis lacinia dolor. Integer mollis placerat metus in adipiscing. Fusce tincidunt sapien in quam vehicula tincidunt. Integer id ligula ante, interdum sodales enim. Suspendisse quis erat ut augue porta laoreet."],
["paragraph", "Sed pellentesque lacus vel sapien facilisis vehicula. Quisque non lectus lacus, at varius nibh. Integer porttitor porttitor gravida. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus accumsan ante tincidunt magna dictum vulputate. Maecenas suscipit commodo leo sed mattis. Morbi dictum molestie justo eu egestas. Praesent lacus est, euismod vitae consequat non, accumsan in justo. Nam rhoncus dapibus nunc vel dignissim."],
["paragraph", "Nulla id neque ac felis tempor pretium adipiscing ac tortor. Aenean ac metus sapien, at laoreet quam. Vivamus id dui eget neque mattis accumsan. Aliquam aliquam lacinia lorem ut dapibus. Fusce aliquam augue non libero viverra ut porta nisl mollis. Mauris in justo in nibh fermentum dapibus at ut erat. Maecenas vitae fermentum lectus. Nunc dolor nisl, commodo a pellentesque non, tincidunt id dolor. Nulla tellus neque, consectetur in scelerisque vitae, cursus vel urna. Phasellus ullamcorper ultrices nisi ac feugiat."],
["table",
{"header":[{"color":[100, 100, 100]}, "FOO"], "cellSpacing":20},
["foo",
["cell",
["phrase",
{"style":"italic",
"size":18,
"family":"halvetica",
"color":[200, 55, 221]},
"Hello Clojure!"]],
"baz"],
["foo1", ["cell", {"color":[100, 10, 200]}, "bar1"], "baz1"],
["foo2", "bar2",
["cell",
["table",
["Inner table Col1", "Inner table Col2", "Inner table Col3"]]]]],
["paragraph", "Suspendisse consequat, mauris vel feugiat suscipit, turpis metus semper metus, et vulputate sem nisi a dolor. Duis egestas luctus elit eget dignissim. Vivamus elit elit, blandit id volutpat semper, luctus id eros. Duis scelerisque aliquam lorem, sed venenatis leo molestie ac. Vivamus diam arcu, sodales at molestie nec, pulvinar posuere est. Morbi a velit ante. Nulla odio leo, volutpat vitae eleifend nec, luctus ac risus. In hac habitasse platea dictumst. In posuere ultricies nulla, eu interdum erat rhoncus ac. Vivamus rutrum porta interdum. Nulla pulvinar dui quis velit varius tristique dignissim sem luctus. Aliquam ac velit enim. Sed sed nisi faucibus ipsum congue lacinia. Morbi id mi in lectus vehicula dictum vel sed metus. Sed commodo lorem non nisl vulputate elementum. Fusce nibh dui, auctor a rhoncus eu, rhoncus eu eros."],
["paragraph", "Nulla pretium ornare nisi at pulvinar. Praesent lorem diam, pulvinar nec scelerisque et, mattis vitae felis. Integer eu justo sem, non molestie nisl. Aenean interdum erat non nulla commodo pretium. Quisque egestas ullamcorper lacus id interdum. Ut scelerisque, odio ac mollis suscipit, libero turpis tempus nulla, placerat pretium tellus purus eu nunc. Donec nec nisi non sem vehicula posuere et eget sem. Aliquam pretium est eget lorem lacinia in commodo nisl laoreet. Curabitur porttitor dignissim eros, nec semper neque tempor non. Duis elit neque, sagittis vestibulum consequat ut, rhoncus sed dui."],
["anchor", {"style":{"size":15}, "leading":20}, "some anchor"],
["anchor", ["phrase", {"style":"bold"}, "some anchor phrase"]],
["anchor", "plain anchor"],
["chunk", {"style":"bold"}, "small chunk of text"],
["phrase", "some text here"],
["phrase",
{"style":"italic",
"size":18,
"family":"halvetica",
"color":[0, 255, 221]},
"Hello Clojure!"],
["chapter", ["paragraph", "Second Chapter"]],
["paragraph", {"keep-together":true, "indent":20},
"a fine paragraph"],
["list", {"roman":true}, ["chunk", {"style":"bold"}, "a bold item"],
"another item", "yet another item"],
["chapter", "Charts"],
["chart",
{"type":"bar-chart",
"title":"Bar Chart",
"x-label":"Items",
"y-label":"Quality"},
[2, "Foo"], [4, "Bar"], [10, "Baz"]],
["chart",
{"type":"line-chart",
"title":"Line Chart",
"x-label":"checkpoints",
"y-label":"units"},
[1, 10], [2, 20], [3, 15], [4, 25]]]
```
--------------------------------
### Adding Superscript Text in JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Examples of using the 'superscript' tag to create text chunks rendered in superscript. Optional metadata like 'style' can be used to apply font styles.
```javascript
["superscript", "some superscript text"]
```
```javascript
["superscript", {"style":"bold"}, "some bold superscript text"]
```
--------------------------------
### Adding Subscript Text in JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Examples of using the 'subscript' tag to create text chunks rendered in subscript. Optional metadata like 'style' can be used to apply font styles.
```javascript
["subscript", "some subscript text"]
```
```javascript
["subscript", {"style":"bold"}, "some bold subscript text"]
```
--------------------------------
### Defining Chart Data Series (Clojure)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
These vectors represent data series, likely used as input for generating charts. Each series starts with a name followed by pairs of data points.
```Clojure
["Foo", [1, 10], [2, 13], [3, 120], [4, 455], [5, 300], [6, 600]],
["Bar", [1, 13], [2, 33], [3, 320], [4, 155], [5, 200], [6, 300]]
```
--------------------------------
### Defining a Time-Series Line Chart (Custom Format) using JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This snippet shows a time-series line chart definition using a custom date format specified by 'time-format'. The example uses the 'MM/yy' format for the x-axis date points.
```javascript
["chart",
{"type":"line-chart",
"time-series":true,
"time-format":"MM/yy",
"title":"Time Chart",
"x-label":"time",
"y-label":"progress"},
["Occurances", ["01/11", 200], ["02/12", 400], ["05/12", 350],
["11/13", 600]]]
```
--------------------------------
### Creating an Anchor with Style and Leading (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Demonstrates creating an anchor element with specified font size style and leading space. The content is a simple string.
```javascript
["anchor", {"style":{"size":15}, "leading":20}, "some anchor"]
```
--------------------------------
### Creating a Chunk with Bold Style (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Demonstrates creating a small text chunk with a bold font style applied via metadata.
```javascript
["chunk", {"style":"bold"}, "small chunk of text"]
```
--------------------------------
### Adding Dependency with Gradle
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Instructions for adding the json-to-pdf library as a dependency in a Gradle project by specifying the repository and compile dependency.
```Gradle
repositories {
jcenter()
maven {
url 'http://clojars.org/repo'
}
}
compile "json-to-pdf:json-to-pdf:0.8.3"
```
--------------------------------
### Creating a Chapter with String Content (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Illustrates creating a chapter element using a simple string as its title or content.
```javascript
["chapter", "First Chapter"]
```
--------------------------------
### Configuring a Pie Chart (Clojure)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This vector defines a pie chart configuration. It includes the chart type, title, and data points represented as pairs of labels and values.
```Clojure
["chart", {"type":"pie-chart", "title":"Big Pie"}, ["One", 21],
["Two", 23], ["Three", 345]]
```
--------------------------------
### Adding Dependency with Maven
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Instructions for adding the json-to-pdf library as a dependency in a Maven project by adding the Clojars repository and the dependency coordinates.
```Maven
clojars.org
http://clojars.org/repo
json-to-pdf
json-to-pdf
0.8.3
```
--------------------------------
### Creating an Anchor with Nested Phrase Content (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Shows how to create an anchor element where the content is another nested document section, specifically a phrase with bold style.
```javascript
["anchor", ["phrase", {"style":"bold"}, "some anchor phrase"]]
```
--------------------------------
### Creating a Chapter with Nested Paragraph Content (JavaScript)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Shows how to create a chapter element where the content is a nested paragraph section.
```javascript
["chapter", ["paragraph", "Second Chapter"]]
```
--------------------------------
### Available JSON Page Sizes
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Lists the valid string values that can be used for the 'size' field within the JSON document metadata to specify the page dimensions.
```JSON
"a0"
"a1"
"a10"
"a2"
"a3"
"a4"
"a5"
"a6"
"a7"
"a8"
"a9"
"arch-a"
"arch-b"
"arch-c"
"arch-d"
"arch-e"
"b0"
"b1"
"b10"
"b2"
"b3"
"b4"
"b5"
"b6"
"b7"
"b8"
"b9"
"crown-octavo"
"crown-quarto"
"demy-octavo"
"demy-quarto"
"executive"
"flsa"
"flse"
"halfletter"
"id-1"
"id-2"
"id-3"
"large-crown-octavo"
"large-crown-quarto"
"ledger"
"legal"
"letter"
"note"
"penguin-large-paperback"
"penguin-small-paperback"
"postcard"
"royal-octavo"
"royal-quarto"
"small-paperback"
"tabloid"
```
--------------------------------
### Defining a Pie Chart using JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This snippet provides the JSON structure for defining a simple pie chart. It includes properties for chart type, title, and data points represented as slices with labels and values.
```javascript
["chart", {"type":"pie-chart", "title":"Big Pie"}, ["One", 21],
["Two", 23], ["Three", 345]]
```
--------------------------------
### Creating Spacers (New Lines) in JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Illustrates how to use the 'spacer' tag to insert a specified number of new lines into the document. If no number is provided, it defaults to one new line.
```javascript
["spacer"]
```
```javascript
["spacer", 5]
```
--------------------------------
### Configuring a Time Series Line Chart (Clojure)
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This vector defines a line chart configuration, specifically for time series data. It includes the chart type, title, axis labels, and data points with timestamps and values.
```Clojure
["chart",
{"type":"line-chart",
"time-series":true,
"title":"Time Chart",
"x-label":"time",
"y-label":"progress"},
["Incidents", ["2011-01-03-11:20:11", 200],
["2011-01-03-11:25:11", 400], ["2011-01-03-11:35:11", 350],
["2011-01-03-12:20:11", 600]]]
```
--------------------------------
### Defining a Bar Chart using JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This snippet shows the JSON structure for defining a simple bar chart. It includes properties for chart type, title, background color, axis labels, and data points.
```javascript
["chart",
{"type":"bar-chart",
"title":"Bar Chart",
"background":[255,255,255],
"x-label":"Items",
"y-label":"Quality"}, [2, "Foo"], [4, "Bar"], [10, "Baz"]]
```
--------------------------------
### Generating PDF from JSON in Java
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Demonstrates how to use the JsonPDF class in Java to generate PDF files from JSON strings, including writing to a file and a stream, and how to integrate custom page events like headers/footers.
```Java
import cljpdf.text.BadElementException;
import cljpdf.text.Document;
import cljpdf.text.Image;
import cljpdf.text.pdf.PdfWriter;
import org.yogthos.JsonPDF;
import cljpdf.text.pdf.PdfPageEventHelper;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.MalformedURLException;
public class Main {
public static void main(String[] args) throws Exception {
String jsonDoc1 = "[{}, [\"paragraph\", \"hello world\"]]";
String jsonDoc2 = "[{\"pages\":true,\"orientation\":\"landscape\"}, [\"paragraph\", \"hello world\"]]";
JsonPDF.writeToFile(jsonDoc1, "out.pdf", null);
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
JsonPDF.writeToStream(new ByteArrayInputStream(jsonDoc1.getBytes()),
new FileOutputStream("outstream.pdf"), null);
System.out.println(new File(".").getAbsolutePath());
JsonPDF.writeToFile(jsonDoc1, "out.pdf", new HeaderFooter("resources/mandelbrot.jpg"));
}
static class HeaderFooter extends PdfPageEventHelper {
private Image img;
public HeaderFooter(String imagePath)
throws BadElementException, MalformedURLException, IOException {
ClassLoader classLoader = getClass().getClassLoader();
File file = new File(imagePath);
this.img = Image.getInstance(file.getPath());
this.img.scaleToFit(100, 100);
this.img.setAbsolutePosition(25,700);
}
@Override
public void onStartPage(PdfWriter writer, Document document) {
try {
writer.getDirectContent().addImage(this.img);
} catch (Exception x) {
x.printStackTrace();
}
}
}
}
```
--------------------------------
### Defining a Standard Line Chart using JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This snippet demonstrates the JSON structure for defining a standard line chart with multiple data series. It includes properties for chart type, title, axis labels, and data points for each series.
```javascript
["chart",
{"type":"line-chart",
"title":"Line Chart",
"x-label":"checkpoints",
"y-label":"units"},
["Foo", [1, 10], [2, 13], [3, 120], [4, 455], [5, 300], [6, 600]],
["Bar", [1, 13], [2, 33], [3, 320], [4, 155], [5, 200], [6, 300]]]
```
--------------------------------
### Defining Sections in JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Demonstrates the structure for defining sections within a PDF document using the 'section' tag. Sections must be parented under chapters or other sections and require a title followed by content. Optional metadata like 'indent' can be applied.
```javascript
["chapter", ["paragraph", {"color":[250, 0, 0]}, "Chapter"],
["section", "Section Title", "Some content"],
["section", ["paragraph", {"size":10}, "Section Title"],
["paragraph", "Some content"], ["paragraph", "Some more content"],
["section", {"color":[100, 200, 50]},
["paragraph", "Nested Section Title"],
["paragraph", "nested section content"]]]]
```
--------------------------------
### Customizing Table Cells in JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Shows how to use the 'cell' tag within tables to apply specific styling or structure to individual cells. Cells can include metadata for color, colspan, rowspan, borders, and can contain other elements, including nested tables.
```javascript
["cell", {"colspan":2}, "Foo"]
```
```javascript
["cell", {"colspan":3, "rowspan":2}, "Foo"]
```
```javascript
["cell",
["phrase",
{"style":"italic",
"size":18,
"family":"halvetica",
"color":[200, 55, 221]}, "Hello Clojure!"]]
```
```javascript
["cell", {"color":[100, 10, 200]}, "bar1"]
```
```javascript
["cell",
["table",
["Inner table Col1", "Inner table Col2", "Inner table Col3"]]]
```
--------------------------------
### Representing Strings as Paragraphs
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
Shows that a simple string literal in the JSON structure will be automatically interpreted and rendered as a paragraph in the generated PDF.
```text
"this text will be treated as a paragraph"
```
--------------------------------
### Defining a Time-Series Line Chart (Default Format) using JSON
Source: https://github.com/yogthos/json-to-pdf/blob/master/README.md
This snippet illustrates the JSON structure for a time-series line chart. Setting 'time-series' to true requires x-axis data points to be dates. The default date format 'yyyy-MM-dd-HH"mm:ss"' is used here.
```javascript
["chart",
{"x-label":"time",
"y-label":"progress",
"time-series":true,
"title":"Time Chart",
"type":"line-chart"},
["Incidents", ["2011-01-03-11:20:11", 200],
["2011-02-11-22:25:01", 400], ["2011-04-02-09:35:10", 350],
["2011-07-06-12:20:07", 600]]]
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.