The purpose of this guide is to provide an example of using Aussom Java Interface (AJI) to load an external Java library and use it in an Aussom application.
Before we get started on coding, we need to download the Apache PDFBox Java library. Download it and then save it into the same directory where the Aussom application file will be created.
In the same directory, create a file named pdfbox.aus
. Inside that file create a new class with a main function. The code below fist loads the JAR file. It then creates the new Java PDDocument object. It then saves it to test.pdf, logs a line to standard out, and then closes the PDF doc and ends. This code produces a new empty PDF file.
include app;
include aji;
class PdfBoxTest {
public main(args) {
// Load the JAR file onto the classpath.
app.loadJar("pdfbox-app-3.0.3.jar");
// Create a Java PDDocument object.
obj = aji.newObj("org.apache.pdfbox.pdmodel.PDDocument");
// Save the document by calling the save() function
// with the file name argument.
obj.invoke("save", "test.pdf");
c.log("Created PDF: test.pdf");
// Close the doc
obj.invoke("close");
}
}
After saving the file, run it from the CLI. If all goes well you should also find a blank pdf file named test.pdf
.
$ aussom pdfbox.aus
Created PDF: test.pdf
$
This is a very simple example but it demonstrates dynamically loading a new JAR on the classpath, creating a Java object from that JAR, and then invoking member functions on the object. A little more reading in the PDFBox API docs, and you should be able to create a variety of content inside the PDF.