Code Monkey home page Code Monkey logo

pdf-builder's Introduction

License: GPL v3 Build Status

pdf-builder

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.

Usage

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);

Development Notes

To build from source:

git clone [email protected]: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.

pdf-builder's People

Contributors

cakism avatar geertijewski avatar jasin avatar lamba92 avatar timrs2998 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.