Create Pdf of a Screen

Hi!

I need to make a printscreen and save it as a pdf file.

I have tried “[color=#0000FF]system.print.printToImage(event.source.parent, “Screen.jpg”)[/color]” to generate an image.

And also I have tried this code:

[color=#0000FF]windowName = system.nav.getCurrentWindow()
try:
rc = system.gui.getWindow(windowName).getRootContainer()
job = system.print.createPrintJob(rc)
job.setMargins(0.5)
job.showPageFormat = 0
job.orientation = system.print.LANDSCAPE
job.print()
except:
# window not opened
pass[/color]

If I have the “Pdf Creator” as primary printer, it works. But I would like to ask if there is other way to generate a pdf file without using the “Pdf Creator”??

Maybe with “[color=#0000FF]fpmi.system.execute()[/color]” or importing a library…

Thanks for the help!

I turned the free java library iText into a module. Then used their API to take all the components on the screen and turn it into a PDF.

http://itextpdf.com/

Good luck.

Hi Jonathan,

I have tried to import an external library like you say but it doesn’t compile and I’m trying to make it work…

I have tried this one but it doesn’t seem to work:
blog.pythonlibrary.org/2012/ … n-library/

Is there a chance of sharing a sample code and the module you used with us?? It would be great!!

Thanks again!

you cannot just use the import in the script language. you have to first create a Ignition module that includes the jar files. then send the module to inductive automation to be signed and then you import the module into the Ignition gateway webpage. at that point you will then have access to the jar library imports.

  1. download the itext jar
  2. in the same location as the itext jar create a file called module.xml
  3. in the module.xml file place the following text with the relevant information filled out. if there more than one jar repeat the jar scope line for each jar
<?xml version="1.0" encoding="UTF-8"?>
<modules>
	<!-- A module xml file can define multiple modules -->
	<module>
		<id>itext</id>
		<name>iText</name>
		<description>Adds the iText java library to the client, gateway, and designer scopes.</description>
		<version>Version of the Module goes here</version>
		<requiredignitionversion>version of ignition goes here</requiredignitionversion>
		<requiredframeworkversion>4</requiredframeworkversion>
		<freemodule>true</freemodule>
		<jar scope="DCG">itextpdf.jar</jar>
		<depends scope="G">fpmi</depends>
	</module>
</modules>
  1. Zip the module.xml file and all the jar files together.
  2. rename the extension on the zipped file to modl
  3. send the module into inductive automation for signing
  4. take the signed module you receive back and import it into the Ignition gateway

hope this helps

Hi Jonathan,

Thanks you for all the help. I have followed all your steps, but now I’m stuck trying to register the module I have created.

  1. I have downloaded the latest “itext” file and uncompress all the jars in a Folder.
  2. I have created the module.xml with the code:

[color=#0000FF]<?xml version="1.0" encoding="UTF-8"?>

itext iText Adds the iText java library to the client, gateway, and designer scopes. 1.0.0 7.4.0 4 itextpdf-5.4.0.jar itextpdf-5.4.0-javadoc.jar itextpdf-5.4.0-sources.jar itext-pdfa-5.4.0.jar itext-pdfa-5.4.0-javadoc.jar itext-pdfa-5.4.0-sources.jar itext-xtra-5.4.0.jar itext-xtra-5.4.0-javadoc.jar itext-xtra-5.4.0-sources.jar [/color]
  1. Finally, I have compressed all in a rar file, and named it “PDF_Creator.modl”.

Now I’m trying to register the module at the Ignition Website → Configuration → Modules → Install a module… but appears the error “Error loading the module. See log for details”. I can’t find the log anywhere…

Can you help me in these final step? Thanks again.


did you fill out the highlighted parts in the xml file?

when you download the file from itext you probably need to unzip it to get the jar files.

you cannot put itext.zip in the scope line you need to put the jar file there “jarfilename.jar”

Hi Jonathan,

I realized of what you said after I wrote the reply! I have actualized my post with the unzipped jars, but it doesn’t change the result at the Ignition Website!! Can you tell where is the log where I can see the details of the error?? In the Console doesn’t appear nothing…

Thanks again!!

did you send the module in to get signed. if not you need to get a developer license key.

you can register as a developer her

https://www.inductiveautomation.com/developers/register

you can log in to get your module signed here

https://www.inductiveautomation.com/developers/login

I am not sure were to look if your console is not showing any errors.

Hi again,

I have tried to Login at the “Developer Portal Login” and it says that I don’t have sufficient privileges to Loggin… what can I do with that?

register as a developer first. you the top link i posted.

Hi again,

At last I made it!!

The key to register the modl in Gateway is: register as a developer, be careful with the tabulations in the xml file and use the example of Jonathan changing only the name of your jar. And then create the script using the names of your imports:

[color=#0000FF]import com.itextpdf.text.Document
my_file = com.itextpdf.text.Document()[/color]

Thanks again for all the support you have given me!