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:
- Extract the javatest folder.
- In command line, navigate to the javatest parent folder, and run the testpackage.Text.class, e.g.
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).
- In IRIS SMP navigate to System > Configuration > External Language Servers.
- Click Add External Language Server, give it a name, port (that is not blocked by your firewall)
Set the Java home directory if not part of your PATH.
Click Save. - Click Start and make sure your gateway is running by checking the activity log.
- You can also do a check from terminal:
USER>w ##class(%Net.Remote.Java.JavaGateway).%Ping("127.0.0.1",12345)
1
Now let's setup IRIS
- Extract the iris folder.
- Import the classes and globals to your USER namespace.
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")
- Make sure the port number matches your external gateway port:
Set host="127.0.0.1"
Set port=12345
Set serviceName="testpackage.ExampleOpenPdf"
- Compile your class.
- In terminal run
d ##class(Sample.Report).GenerateReport()
You should get a "PDF generated" message and a PDF file in your folder.