Creating a PDF from a Text file
Using the Java Gateway to speed development
InterSystems IRIS includes dynamic object gateways for Java, .NET, and (now) Python. These gateways allow your IRIS application to use libraries in these languages, removing the need to create everything from scratch in ObjectScript.
In this example, we use the iTextPdf and Apache PdfBox libraries to read a text file and produce a basic PDF from it. These libraries are deep and rich PDF controls, so a little bit of development could produce an example application that produces far more compelling results for your needs. I've also included a short class file that makes using it from ObjectScript a piece of cake.
The sources for the demo are available in the intersystems-community github hub.
Installing TextToPDF requires that you have access to your IRIS server with sufficient access to work with gateways and classes.
1. Clone this repository
Clone this repository into a directoruy on your IRIS server:
git clone https://github.com/intersystems-community/iris-pdf-generator.git
2. Create a Java Gateway
In the management console, go to System Administration > Configuration > Connectivity > Object Gateways and choose "Create New Gateway"
Object Gateway For: Java Gateway Name: iris-pdf-generator Port: 54545 Class Path: (directory where you cloned the repo)/target/iris-pdf-generator-0.1.0-jar-with-dependencies.jar
Leave all the others as default and click Save.
3. Load the class file
In the management console, make sure you are in the user namespace, go to System Explorer > Classes, and choose "Import". Browse to the directory where you cloned this repo and choose "all files" from the file type dropdown. Select the PdfGenerator.cls file. Click "Next", then "Import".
Now that everything is installed, you can use it from IRIS. Open a console and do the following, replacing "" with the name of the directory you cloned this repository into:
set status = ##class(User.PdfGenerator).TextToPdf("<clone dir>\example.txt", "<clone dir>\example.pdf")
That will create
example.pdf as a PDF version of