Skip to content

JQuick-Pdf

Pure Java · Apache-2.0 · Zero browser dependency

Generate chart-rich PDF reports in pure Javano browser, no hand-written chart drawing code

One HTML/CSS-style template plus one ECharts-style chart config, a single data binding, and you get a byte[] back — layout, vector charts and automatic pagination all happen inside one JVM process.

Real output of the code above · page 1 of 2 — JQuick-Pdf
Real output of the code above · page 1 of 2

Not a design mock-up: generated by the sample code — download the PDF and the template source to verify

  • 0 linesof chart drawing code
  • 30+built-in vector chart types
  • 0browser / WebKit / native deps
  • 1JVM process end to end
9 linesAll the core code that produces this report
JOption option = new JOption();
option.title().text("2024年月度营收统计");
JCategoryAxis x = new JCategoryAxis();
x.data("1月", "2月", "3月", "4月", "5月", "6月");
option.xAxis(x); option.yAxis(new JValueAxis());
option.series(new JLine().name("营业收入").data(1860, 1720, 2140));
String svg = JChartRendererFactory.renderChart(JChartType.LINE, option);
byte[] pdf = JQuickPdfFactory.create().bind("svg", svg)
.executeResource("report/monthly.txt"); // template: <svg>${svg}</svg>
Files.write(Paths.get("monthly.pdf"), pdf);

Imports and the main method omitted; the chart takes one line in the template, <svg>${svg}</svg>, configured ECharts-style via JOption.

How does it compare to iText 7?

This comparison is not a knock on iText — it is a great library. But when what you want is "write reports like web pages, charts out of the box", the two differ by an order of magnitude in effort.

ConcernJQuick-PdfiText 7
Getting startedHTML/CSS-style template + data binding — a frontend mindsetBuild document objects element by element in Java
Charts30+ built-in vector charts, configured ECharts-style via JOptionNo built-in chart engine; bring JFreeChart or similar, rasterize, then insert
Chinese textBundled CJK fonts, zero configurationFind and register font files yourself
RuntimeOne JVM — no browser, no native librariesPure Java works (chart pipeline needs extra deps)
LicenseApache-2.0 (4.0.0+)AGPL-3.0 community edition; commercial use requires a paid license

9 lines of core code vs three stages of glue code — the gap is exactly the part where the chart enters the document.

JQuick-Pdf is the PDF toolkit of the JQuick ecosystem. It focuses on generating, rendering and exporting PDFs from Java: write a template that looks like HTML with inline CSS, bind your data and get a PDF back — as a byte[], a stream or a file.

Templates are parsed with a self-developed grammar and drawn page by page through Apache PDFBox. The whole pipeline has no browser, no headless Chrome and no native library, which makes it a good fit for services, scheduled jobs and desktop applications.

Module Coordinate Purpose
jquick-pdfx io.github.paohaijiao:jquick-pdfx Parser, renderer, layout engine and the JQuickPdfFactory entry point — enough for most projects
jquick-pdf-css io.github.paohaijiao:jquick-pdf-css CSS model: style properties, units and colours
jquick-pdf-svg io.github.paohaijiao:jquick-pdf-svg SVG / ECharts-style chart generation (30+ chart types)
jquick-pdf-data io.github.paohaijiao:jquick-pdf-data Chart configuration model (JOption, JChart, JTitle, JLegend, …)
jquick-pdf-font io.github.paohaijiao:jquick-pdf-font Bundled CJK fonts, so Chinese text needs no extra configuration
  • Pure Java, no external engine: no WebKit, no Chrome and no operating-system level dependency — a single JVM process renders everything.
  • HTML/CSS-style templates: 14 element types, each accepting inline style="..." attributes.
  • Two naming conventions: minHeight (camelCase) and min-height (standard CSS) are interchangeable and can be mixed in one declaration.
  • Data binding: ${variable} binds plain values while &{resource} references registered resources such as charts, sub-templates and trees.
  • 30+ chart types: bar, line, pie, radar, scatter, box plot, heatmap, candlestick, funnel, gauge, Gantt, word cloud, map, sunburst, treemap, topology and more — all drawn as vectors.
  • Full document capabilities: automatic pagination, table of contents, headers and footers, page numbers, watermarks and PDF encryption.
  • CJK friendly: bundled CJK fonts make Chinese content work out of the box.
  • Modular artefacts: depend only on the parsing and rendering core, then add charts, CSS or fonts on demand.
  • Java 8 compatible: released artefacts target Java 8 bytecode.
<dependency>
<groupId>io.github.paohaijiao</groupId>
<artifactId>jquick-pdfx</artifactId>
<version>4.1.0</version>
</dependency>

Chart support is an optional dependency:

<dependency>
<groupId>io.github.paohaijiao</groupId>
<artifactId>jquick-pdf-svg</artifactId>
<version>4.1.0</version>
</dependency>
import com.github.paohaijiao.executor.JQuickPdfFactory;
import java.nio.file.Files;
import java.nio.file.Paths;
public class HelloDemo {
public static void main(String[] args) throws Exception {
String template = ""
+ "<pdf>"
+ " <body>"
+ " <h1 style=\"fontSize:24;fontColor:blue\">'Hello jquick-pdf'</h1>"
+ " <p>'Customer: '${customer}</p>"
+ " </body>"
+ "</pdf>";
byte[] pdf = JQuickPdfFactory.create()
.bind("customer", "Martin")
.executeContent(template);
Files.write(Paths.get("hello.pdf"), pdf);
}
}

All three methods return a byte[]:

Method Template source
executeContent(String) Template text held in memory
executeResource(String) A classpath resource, for example "report.txt"
executeFile(String) A file on disk, for example "D:/templates/report.txt"

The JQuick-Pdf template grammar defines 18 element types. Their names and support status:

Element Description Support status
paragraph Paragraph container (written as <p> in templates) holding a run of text with inline styles Supported
heading Heading element, corresponding to the six levels <h1> … <h6> Supported
list List container; works with <li> to render ordered or unordered items Supported
table Table; works with <tr> / <th> / <td> to draw rows, columns and cell styles Supported
image Raster image; the source is specified with src Supported
svg Vector graphics; embed charts with ${svg} / &{svg} Supported
div Block container with background, border, padding, size, rotation and flex layout support Supported
span Inline container for styling a fragment of text inside a paragraph Supported
areaBreak Forced page break; content after it is drawn on the next page Supported
button Button control for building interactive PDF forms Supported
checkbox Checkbox control for building interactive PDF forms Supported
comboBoxField Combo-box (drop-down) control for building interactive PDF forms Supported
htmlPageBreak HTML-style page break at the declared position Supported
lineSeparator Horizontal separator line Supported
tab Tab character for tab-stop aligned layout Supported
textArea Multi-line text-area control for building interactive PDF forms Supported
tree Tree structure for rendering hierarchical data Supported
value Text value node: literal text wrapped in single quotes, or a value bound with ${...} Supported

Minimal template snippets for each element (the <pdf><body> root is omitted for brevity).

A paragraph uses <p> and is the block element for ordinary text:

<p style="fontSize:12; lineHeight:1.5">'A paragraph that holds a run of ordinary text.'</p>

Headings use <h1> … <h6>; the smaller the number, the higher the level:

<h1 style="fontSize:20; fontColor:#1f2937">'Level-one heading'</h1>
<h2 style="fontSize:16; fontColor:#374151">'Level-two heading'</h2>

A list uses <list> + <li>, with list-style-type controlling the bullet:

<list style="list-style-type:disc; fontSize:12">
<li>'First unordered item'</li>
<li>'Second unordered item'</li>
</list>

Tables follow the <table> → <tr> → <th> / <td> hierarchy:

<table style="width:100%; fontSize:11">
<tr>
<th style="backgroundColor:#f8f9fa; padding:5px">'Name'</th>
<th style="backgroundColor:#f8f9fa; padding:5px">'Age'</th>
</tr>
<tr>
<td style="padding:5px">'Alice'</td>
<td style="padding:5px">'28'</td>
</tr>
</table>

An image uses <image>; the source comes from src, and width/height are optional:

<image src="logo.png" style="width:120px; height:60px" />

Vector graphics use <svg>, usually bound to a rendered chart string with ${svg}:

<svg style="width:400px; height:300px">${svg}</svg>

<div> is a block container used to group content and style it together (background, border, padding, flex layout, …):

<div style="padding:10px; backgroundColor:#f8f9fa; borderRadius:4px">
<p style="fontSize:12">'A paragraph inside the container.'</p>
</div>

<span> is an inline container for styling a fragment of text inside a paragraph:

<p style="fontSize:12">'Total: '<span style="fontColor:red; fontWeight:bold">'$99.00'</span></p>

<areaBreak> forces a page break; content after it starts on the next page:

<p>'Content on page one'</p>
<areaBreak />
<p>'Content on page two'</p>

<button> renders an interactive button form field; name identifies the field:

<button name="confirm" style="width:80px; height:28px">'Submit'</button>

<checkbox> renders a checkbox form field:

<checkbox name="agreed" />'I have read and agree to the terms'

<comboBoxField> renders a drop-down form field; name identifies the field:

<comboBoxField name="city" style="width:200px; height:24px" />

<htmlPageBreak> inserts an HTML-style page break at its declared position:

<p>'Content before the break'</p>
<htmlPageBreak />
<p>'Content after the break'</p>

<lineSeparator> draws a horizontal separator line:

<lineSeparator style="width:100%; color:#cccccc" />

<tab> inserts a tab character for tab-stop aligned layout:

<p style="fontSize:12">'Name: '<tab />'Alice'</p>

<textArea> renders a multi-line text-area form field:

<textArea name="remark" style="width:300px; height:80px" />

<tree> renders a tree structure; the tree data is passed in via a bound variable:

<tree style="width:100%; fontSize:12">${deptTree}</tree>

value is the grammar-level text node: single-quoted literal text and ${...} bindings both render as the final text:

<p>'Customer: '${customer}</p>

Styles are declared in the element’s style="..." attribute; standard CSS kebab-case names (font-size) and camelCase names (fontSize) are equivalent and can be mixed. Size units accept px, pt, mm, cm and in. Commonly used properties:

Property Description Applies to
width Element width Block elements such as div, table, image
height Element height Block elements such as div, table, image
margin Outer margin — the space between the element and its neighbours All elements
padding Inner padding — the space between content and border Container elements such as div, table, td, list
border Border with width, line style and colour, e.g. 1px solid #cccccc div, table, td, …
background-color Background colour; accepts colour names, #RRGGBB, rgb() / rgba() Container elements such as div, table, td, list
color Text (foreground) colour Text-bearing elements: paragraph, value, table cells
font-size Font size Text-bearing elements
font-family Font family; the bundled CJK fonts render Chinese out of the box Text-bearing elements
text-align Horizontal alignment: left / center / right paragraph, value, td, div
vertical-align Vertical alignment: top / middle / bottom Table cells such as td and container elements
line-height Line height (leading) Text elements such as paragraph, value
font-weight Font weight, e.g. normal / bold Text-bearing elements