OpenPDF Cheatsheet

The first time I had to create PDFs for a customer project (20 years ago, ouch :-O ), I was using iText which was the state of the art library in Java. Bruno Lowagie - who developed iText - has always been helpful answering all my dumb questions. Due to a dispute with the belgium government he changed his license for commercial usage.

One of the sole alternatives was pdfbox which is perfect for low level construction of PDFs...what's missing is the high level API iText was providing. So in 2012 I started a bunch of functions for formatting and layouting to solve this problem in a customer project at this time. Alas, the streaming approach was not suitable for recursive layouts, so I dropped support for that.

Recently I had to create PDF again for customer project and I refused to use the low level pdfbox stuff, so I was looking for a lib that would do the job. I knew that iText 4 - the last free version - had been forked quite a while ago as OpenPDF, so I gave it a try. I still love iText's easy high level approach, but the documentation of the project is... eh, not as perfect as it was for iText. So I was plowing through the examples and made some notes, to get some kind of index of most common use cases, and here my notes with some sample PDFs.

Document

Paragraphs, Chunks

Chunks are the smallest units for text with a given font, color etc. Paragraphs are containers for elements like chunks, images etc.

Lists

Tables

Find many more examples demonstating padding, borders, colors, images, nested Tables in the same package

Images

  • Images PDF

  • Find many more examples demonstating transformation, filter, alignment, etc in the same package

Column Layout

Allows you to organize content in columns like in a newspaper or a table

Links

concatenate PDFs

Watermark

Encryption

encrypt

Be aware that you need to add bouncycastle for encryption

        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcprov-jdk18on</artifactId>
        </dependency>
        <dependency>
            <groupId>org.bouncycastle</groupId>
            <artifactId>bcpkix-jdk18on</artifactId>
        </dependency>

Forms

Find many more examples demonstating buttons, combos, etc in the same package

PDFA

Icons by Icon8