Skip to content

Library makes easier to manually create a PDF document by Apache PDFBox.

Notifications You must be signed in to change notification settings

vkuzel/Simple-PDF-Layout

Repository files navigation

Simple PDF Library

A library which makes it easier to manually create a simple PDF document with Apache PDFBox.

Features

  • HTML-like element model.
  • Reversed Y-axis so a point (0, 0) is at the top-left corner of the page.
  • Basic elements for drawing boxes, texts, tables and arrows.

Getting started

  1. Include the library into your project.

    // build.gradle.kts
    repositories {
        maven("https://jitpack.io")
    }
    
    dependencies {
        implementation("com.github.vkuzel:Simple-PDF-Layout:2.1.2")
    }
  2. Use it

    // Create page of size A4.
    Page page = Page.a4()
            // Create a text box of width 100 points on the page and align it to right.
            .addText(text -> text
                    .setTopLeft(100, 100)
                    .setWidth(100)
                    .setAlignment(Text.Alignment.RIGHT)
                    .setText("Hello World!"))
            // Add an arrow pointing to the the previous element (text).
            .addArrow(arrow -> arrow
                    .setStartElement(arrow.getPrevious()));
    
    // Render text to file.
    Document.renderPageToFile(page, "some-path.pdf");

Box model

Following image was rendered by BoxModelDocumentTest.generateBoxModelDocumentTest() method in this project.

Document box model

About

Library makes easier to manually create a PDF document by Apache PDFBox.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages