Updated sample to make the instructions more clear
Practical sample application showing how to generate PDF documents using IRIS and Java.
OpenPDF allows you to handcraft PDFs instead of relying on HTML to PDF printing.
This gives you complete control over the structure of the PDF.
The code can easily be used to call any java application using the intersystems jdbc library.
The code works on windows and linux.
The IRIS and java source (eclipse project) is included.
This sample uses the USER namespace and assumes you are familiar with IRIS.
IRIS.
IRIS supported Java version.
Let’s make sure your Java is working:
C:\>java -classpath "C:\javatest;C:\javatest\lib\*" testpackage.Test
Call result: %PDF-1.5
You should not get any errors and the output should contain the text ‘%PDF’.
*Do not execute the command from inside the javatest folder itself (the classpath has to contain the root directory, not the package subdirectories).
USER>w ##class(%Net.Remote.Java.JavaGateway).%Ping("127.0.0.1",12345)
1
Now let’s setup IRIS
USER>Do $system.OBJ.Load("c:\iris\classes.xml","ck")
USER>Do $system.OBJ.Load("c:\iris\data.gof")
You should have some classes and data (taken from the Intersystems samples):
3. Edit the Sample.Report class to set your classpath (to the folder you used in 1.1)
We do this because we have multiple external language servers running:
Set ClassPath=##class(%ListOfDataTypes).%New()
Do ClassPath.Insert("C:\javatest\lib\gson-2.8.2.jar")
Do ClassPath.Insert("C:\javatest\lib\openpdf-1.3.32.jar")
Do ClassPath.Insert("C:\javatest\")
Set File=##class(%Stream.FileBinary).%New()
Set sc=File.LinkToFile("C:\javatest\sample.pdf")
Set host="127.0.0.1"
Set port=12345
Set serviceName="testpackage.ExampleOpenPdf"
d ##class(Sample.Report).GenerateReport()
You should get a “PDF generated” message and a PDF file in your folder.