PDFjet Java Examples

Each example links to its source code and to the PDF file it creates. To create the PDF files yourself, run the build-java.cmd or build-java.sh script.

  1. Example_01.java  Example_01.pdf   Drawing English, Greek and Bulgarian text in TextBlock components with borders, rounded corners and highlighted keywords, in a PDF/UA document.
  2. Example_02.java  Example_02.pdf   Drawing Simplified and Traditional Chinese text with the embedded IBM Plex Sans SC and TC fonts, in a PDF/UA document.
  3. Example_03.java  Example_03.pdf   Drawing Japanese and Korean text with the embedded IBM Plex Sans JP and KR fonts, in a PDF/UA document.
  4. Example_04.java  Example_04.pdf   Drawing Arabic, Hebrew, Persian and Thai text, including right to left text blocks, in a PDF/UA document.
  5. Example_05.java  Example_05.pdf   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.
  6. Example_06.java  Example_06.pdf   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.
  7. Example_07.java  Example_07.pdf   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.
  8. Example_08.java  Example_08.pdf   Example showing the location, ascent, descent and end point of text drawn with the TextBlock component.
  9. Example_09.java  Example_09.pdf   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.
  10. Example_10.java  Example_10.pdf   Using the TextBlock component with a fixed height, a background color, a border, highlighted keywords and transparency, in a PDF/UA document.
  11. Example_11.java  Example_11.pdf   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.
  12. Example_12.java  Example_12.pdf   Using the TextColumn component to draw centered and justified paragraphs.
  13. Example_13.java  Example_13.pdf   Using the addCJKParagraph method of the TextColumn class to draw Chinese paragraphs, in a PDF/UA document.
  14. Example_14.java  Example_14.pdf   Using the TextFrame and Paragraph components: paragraphs that mix fonts and colors, numbered paragraphs and highlighted keywords.
  15. Example_15.java  Example_15.pdf   Using the TextFrame class to flow text through three columns on every page, in a PDF/UA document.
  16. Example_16.java  Example_16.pdf   Drawing a menu with paragraphs that mix text styles and colors, raised dollar signs and a rotated label, in a PDF/UA document.
  17. Example_17.java  Example_17.pdf   Setting the whole novel "The Idiot" by Dostoyevsky as a book of 745 A5 pages, with a text frame that flows onto new pages.
  18. Example_18.java  Example_18.pdf   Paragraphs written with the inline markup of Markdown, **bold**, *italic*, `code` and [links](url), drawn in their fonts by Markup.
  19. Example_19.java  Example_19.pdf   A Markdown text drawn down the pages by Markdown as a PDF/UA document, with its headings, lists, quote, code, table and image tagged.
  20. Example_20.java  Example_20.pdf   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.
  21. Example_21.java  Example_21.pdf   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.
  22. Example_22.java  Example_22.pdf   Drawing a table whose cells hold text columns of English and Greek paragraphs.
  23. Example_23.java  Example_23.pdf   Adding points with URI Action to Table cells, in a PDF/A-1a document.
  24. Example_24.java  Example_24.pdf   Using the BigTable class to draw a large CSV file on more than 2,500 pages.
  25. Example_25.java  Example_25.pdf   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.
  26. Example_26.java  Example_26.pdf   Using the Chart component to draw a scatter chart with a trend line, and a table that lists the chart points.
  27. Example_27.java  Example_27.pdf   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.
  28. Example_28.java  Example_28.pdf   Drawing a donut chart from the values of its slices.
  29. Example_29.java  Example_29.pdf   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.
  30. Example_30.java  Example_30.pdf   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.
  31. Example_31.java  Example_31.pdf   Using the Stamp and Container components to draw rotated, scaled and nested content.
  32. Example_32.java  Example_32.pdf   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.
  33. Example_33.java  Example_33.pdf   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.
  34. Example_34.java  Example_34.pdf   Drawing a letterhead with a logo read from a PDF file, a maple leaf drawn as a path with curves, and a QR code.
  35. Example_35.java  Example_35.pdf   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.
  36. Example_36.java  Example_36.pdf   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.
  37. Example_37.java  Example_37.pdf   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.
  38. Example_38.java  Example_38.pdf   Drawing a PDF417 barcode that holds a whole source file, with an explanation and a caption, in a PDF/UA document.
  39. Example_39.java  Example_39.pdf   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.
  40. Example_40.java  Example_40.pdf   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.
  41. Example_41.java  Example_41.pdf   Adding nested and automatically numbered bookmarks to the outline of a guide to the PDF file structure, in a PDF/UA document.
  42. Example_42.java  Example_42.pdf   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.
  43. Example_43.java  Example_43.pdf   Using the CheckBox and RadioButton components to draw a survey.
  44. Example_44.java  Example_44.pdf   Using the Form and Field classes to draw a shipment request, with rows of fields and a value that continues on a second line.
  45. Example_45.java  Example_45.pdf   Adding a "DRAFT" watermark to every page of a two-page document that is PDF/A-3a and PDF/UA-1.
  46. Example_46.java  Example_46.pdf   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.
  47. Example_47.java  Example_47.pdf   Encrypting a PDF with user and owner passwords and permissions. The passwords are "hello" and "world".
  48. Example_48.java  Example_48.pdf   Opening an existing PDF and writing semi-transparent text on every page.
  49. Example_49.java  Example_49.pdf   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.
  50. Example_50.java  Example_50.pdf   Example showing how to open existing PDF form and fill it in.