PDF builder written in Kotlin with a statically typed DSL. Inspired by Craig's document-builder library. Under the hood, it relies on Apache PDFBox to create the pdf files.
Both pdf-build and Apache PDFBox are required dependencies. Include the following in your build.gradle.kts:
repositories {
maven { url = uri("https://maven.pkg.github.com/timrs2998/pdf-builder") }
}
dependencies {
implementation("com.github.timrs2998:pdf-builder:<latest version>")
implementation("org.apache.pdfbox:pdfbox:<latest apache pdfbox version>")
}
and you can use the library in Kotlin with its DSL:
val pdDocument = document {
text("Hello")
text("Hello, color is red!") {
fontColor = Color(1f, .1f, .1f)
}
table {
row {
text("r1 c1")
text("r1 c2")
}
row {
text("r2 c1")
text("r2 c2")
}
border = Border(1f, 2f, 3f, 4f, Color.GREEN, Color.RED, Color.BLUE, Color.BLACK)
}
}
pdDocument.use { pdDocument ->
pdDocument.save("output.pdf")
}
or Java without a DSL:
Document document = new Document();
TextElement t1 = new TextElement("Hello");
TextElement t2 = new TextElement("Hello, color is red!");
t2.setFontColor(new Color(1f, .1f, .1f));
document.getChildren().add(t1);
document.getChildren().add(t2);
To build from source:
git clone git@github.com:timrs2998/pdf-builder.git
cd pdf-builder/
./gradlew build
To release a new version, use GitHub to create release tags in "v1.0.0" format matching build.gradle.kts. GitHub Actions will build and publish to the GitHub Packages registry.