Learn PDFjet for Java by example.

50 ready-to-run examples, from a first page of text to tables thousands of pages long. Each one shows its complete source code and the PDF it creates. All of them come with PDFjet Core, ready to build and run.


Example_01

Drawing English, Greek and Bulgarian text in TextBlock components with borders, rounded corners and highlighted keywords, in a PDF/UA document.

Example_02

Drawing Simplified and Traditional Chinese text with the embedded IBM Plex Sans SC and TC fonts, in a PDF/UA document.

Example_03

Drawing Japanese and Korean text with the embedded IBM Plex Sans JP and KR fonts, in a PDF/UA document.

Example_04

Drawing Arabic, Hebrew, Persian and Thai text, including right to left text blocks, in a PDF/UA document.

Example_05

Fonts that are not embedded: the core fonts, Helvetica, Times and Courier, and Chinese, Japanese and Korean in the Adobe CJK fonts, which keep a document very small, a few kilobytes, and what they cost: the viewer supplies them, so the text does not look the same everywhere, and the document cannot be PDF/A or PDF/UA.

Example_06

Embedded fonts: the same words in five weights of IBM Plex Sans, and why embedded fonts are better than the core fonts, in a PDF/UA document.

Example_07

Reading fonts from .otf and .ttf files: any OpenType or TrueType file on the computer is a font for PDFjet, and a TrueType font is embedded as a subset of the glyphs a document draws.

Example_08

The location, ascent, descent and end point of text drawn with the TextBlock component.

Example_09

Drawing chemical formulas with CompositeTextLine: the digits of a formula are subscripts, the charge of an ion and the mass number of an isotope are superscripts, and each formula is one structure element of the tagged document.

Example_10

Using the TextBlock component with a fixed height, a background color, a border, highlighted keywords and transparency, in a PDF/UA document.

Example_11

Using the TextBlock component to draw a description next to each of two maps, with each row starting below the taller of the image and the text.

Example_12

Using the TextColumn component to draw centered and justified paragraphs.

Example_13

Using the addCJKParagraph method of the TextColumn class to draw Chinese paragraphs, in a PDF/UA document.

Example_14

Using the TextFrame and Paragraph components: paragraphs that mix fonts and colors, numbered paragraphs and highlighted keywords.

Example_15

Using the TextFrame class to flow text through three columns on every page, in a PDF/UA document.

Example_16

Drawing a menu with paragraphs that mix text styles and colors, raised dollar signs and a rotated label, in a PDF/UA document.

Example_17

Setting the whole novel "The Idiot" by Dostoyevsky as a book of 745 A5 pages, with a text frame that flows onto new pages.

Example_18

Paragraphs written with the inline markup of Markdown, **bold**, *italic*, `code` and [links](url), drawn in their fonts by Markup.

Example_19

A Markdown text drawn down the pages by Markdown as a PDF/UA document, with its headings, lists, quote, code, table and image tagged.

Example_20

Using the Table component to draw a CSV file on several pages, with an image and a barcode in its cells and a "Page X of N" footer.

Example_21

Drawing two tables: reading scores with two header rows, a header cell that spans two columns and cell background colors, and a table whose cells span columns and rows with setColSpan and setRowSpan.

Example_22

Drawing a table whose cells hold text columns of English and Greek paragraphs.

Example_23

Links in table cells, in a PDF/A-1a document.

Example_24

Using the BigTable class to draw a large CSV file on more than 2,500 pages.

Example_25

A line chart: a Chart with a Series for each line, drawn with setDrawPath, of the electric vehicles of the data file by model year and by kind.

Example_26

Using the Chart component to draw a scatter chart with a trend line, and a table that lists the chart points.

Example_27

Drawing bar charts: a horizontal bar chart of the ten longest rivers with its values inside the bars and a color key, and charts with vertical bars, grouped and stacked.

Example_28

Drawing a donut chart from the values of its slices.

Example_29

The shapes PDFjet draws, each under its name: lines with dashes and caps, rectangles with square and rounded corners, the markers of charts, an ellipse, an arc, a path of Bézier curves and a filled path, and text at every angle around a point.

Example_30

Drawing with transparency: opaque and half transparent rectangles, a fill at four levels of alpha, and strokes and fills that are transparent on their own.

Example_31

Using the Stamp and Container components to draw rotated, scaled and nested content.

Example_32

Embedding JPEG, PNG and BMP images: a JPEG, a PNG and a BMP at their own sizes, a CMYK JPEG, then a PNG of each color type and bit depth, the two ways a PNG carries transparency, and the pHYs chunk that asks for a size.

Example_33

Using the SVGImage component to draw a map of Europe scaled to fit the page, and a set of icons, each labeled with its name.

Example_34

Drawing a letterhead with a logo read from a PDF file, a maple leaf drawn as a path with curves, and a QR code.

Example_35

Using PDF layers (optional content groups) that can be shown or hidden: a relief map of Europe, lines of latitude and longitude that are not printed, and capital cities.

Example_36

Drawing labeled Code 128, Code 39, UPC-A and EAN-13 linear barcodes, and barcodes drawn from top to bottom and from bottom to top.

Example_37

Drawing two-dimensional barcodes: a QR code with each of the four error correction levels, GS1 data as a GS1 Digital Link, and Data Matrix symbols of a web address, UTF-8 text, a rectangle, a larger symbol and GS1 data.

Example_38

Drawing a PDF417 barcode that holds a whole source file, with an explanation and a caption, in a PDF/UA document.

Example_39

Drawing the pages of a document first and finishing them last: the contents page is drawn after the map pages but comes first, and a "Page X of N" footer goes on every page once the number of pages is known.

Example_40

Linking a contents page to chapters and back with "Destinations" and "Go To" actions on text, a box and an image, in a PDF/UA document.

Example_41

Adding nested and automatically numbered bookmarks to the outline of a guide to the PDF file structure, in a PDF/UA document.

Example_42

Attaching an image and a source file to a page, and adding a note, a link and polygon, square and circle annotations, each next to a label.

Example_43

Using the CheckBox and RadioButton components to draw a survey.

Example_44

Using the Form and Field classes to draw a shipment request, with rows of fields and a value that continues on a second line.

Example_45

Adding a "DRAFT" watermark to every page of a two-page document that is PDF/A-3a and PDF/UA-1.

Example_46

An invoice that is also data: a PDF/A-3A document that carries factur-x.xml, as the e-invoice standards Factur-X and ZUGFeRD ask, with an SVG logo, a table of items with its totals and a QR code a banking app scans to pay.

Example_47

Encrypting a PDF with user and owner passwords and permissions. The passwords are "hello" and "world".

Example_48

Opening an existing PDF and writing semi-transparent text on every page.

Example_49

Merging existing PDF documents into one after a cover page drawn with PDFjet, and splitting a document into one PDF for each of its pages and into its pages in reverse order.

Example_50

Opening an existing PDF form and filling it in.

©2026 PDFjet Software.

What our clients are saying:

"I tried to use three other open source PDF libraries, but their source code is not well documented and so "object-oriented" it's proven nearly impossible to read and modify. In contrast I found the PDFjet source code very simple, clean, logical and easy to understand. The fact that it came with very liberal open source license is a huge bonus. The commercial version is very reasonably priced and there are NO ROYALTIES. I wish I had discovered this excellent product earlier."

Gary D. Amundson

Android Developer



On the Web:

"[PDFjet] has a simple and intuitive API and supports a wide range of PDF features, including text, images, and tables. PDFjet also has a low memory footprint, which makes it a great choice if you need to generate PDFs in a memory-constrained environment."

Docsfold (2023)



"I took a look at what was on offer, open source, closed source and commercial. I went for a lib called PDFJet. This is a fairly mature Java pdf library that has been ported over to .Net. It's fairly cheap and whilst it lacks a lot of in depth examples, there are quite a few available on their website. The support is really good too - if you have a question, the guys are able to provide feedback very quickly. It is very well featured, but I am basically using it to generate tables from datatables. I have been using it in earnest for about a week now, so I will try and post some examples of how it can be used here. There are two ways of creating a table with PDFJet, you can use a delimited text file holding the data you need or you can build a table programatically. Doing it in the code is tricky ... however, I am very impressed with this library and the things it can do."

Raphael's Blog