@PGriffith I'm looking to use the pdf viewer component to add comments etc. with the utility panel to a pdf report then save it to the current file path, not save as with a different name. Any suggestions on how to do this, any alternatives if not. If IcePDF Pro is required, where is that installed, on the gateway or every client that needs it? Thanks.
You would have to purchase and provide an IcePDF Pro .jar on the classpath of every client; ICESoft separated the open-source core of their PDF viewer from their proprietary ‘font-engine’ and PDF write support. However, it looks like ICESoft is no longer selling new copies of IcePDF pro, so it’ s not really an option.
Within Vision, I don’t think there are a lot of options. The PDF support inside of the web browser module is just whatever Chromium has, and doesn’t have any support for annotation/markup, to my knowledge. You’d have to find some other Java Swing compatible PDF viewer/editor; or install a separate PDF editor on client machines and launch it in an editing mode, which is obviously a much worse user experience than directly editing within Ignition.
I did see that I can use the pdf viewer to mark up the report then use the print function to print to pdf. It isn’t ideal, but it’s something. Is there anyway to auto feed the file name and path during this process?
Try exploring the PrintHelper
object (${referenceToPDFViewer}.controller.viewModel.printHelper
); specifically it has two methods org.icepdf.ri.common.PrintHelper#getDocAttributeSet
and org.icepdf.ri.common.PrintHelper#getPrintRequestAttributeSet
that might be useful to pre-populate information about the print job before the dialog opens.
I looked at these links, but I have no idea on how to use them.
http://www.icesoft.org/wiki/display/PDF/Print+Services
http://res.icesoft.org/docs/icepdf/latest/viewer/index.html
Filename in particular looks like it should be set by DocumentName
- so setting it each time the file path changes would be something like:
if event.propertyName == "filePath":
from javax.print.attribute.standard import DocumentName, JobName
printHelper = event.source.controller.viewModel.printHelper
docAttributes = printHelper.docAttributeSet
docAttributes.add(DocumentName("someDocumentName", system.util.getLocale()))
printAttributes = printHelper.printRequestAttributeSet
printAttributes.add(JobName("someJobName", system.util.getLocale()))
I have no idea if this will work. I tested locally with the built-in-to-Windows ‘Microsoft Print to PDF’ driver, and it didn’t; some google suggests that it might just not be possible to prepopulate a filename for that dialog, which is a shame. Other print to PDF drivers may behave differently.
Appreciate the script, but it doesn’t work like you mentioned. The save function pulls in the file name of the current pdf shown and would be the ticket. It is a total bummer that it can’t be used or even purchased for use. I can still use the print to PDF driver, but it would rely on the user selecting the correct save location and filename
I also tried an external button with
job = system.print.createPrintJob(event.source.parent.getComponent('PDF Viewer'))
job.setPrinterName('Microsoft Print to PDF')
job.print()
It worked but the whole component was saved as an image in pdf format
Any way to get the pdf as bytes from the component and save that
@PGriffith
Using this snippet isn’t what I wanted, but it works pretty well. I have an edit button that opens the pdf in adobe where the user can mark up the pdf and save without entering any file paths or names. It is pretty quick and much less painful than the print to pdf method.
filePath = event.source.parent.getComponent('PDF Viewer').filePath
system.util.execute(["C:\Program Files (x86)\Adobe\Reader 11.0\Reader\AcroRd32.exe", filePath])
One last question, is there a way to refresh the selected pdf without selecting another file then come back to the one edited to show the changes?
EDIT To refresh I just set the file path to blank then set it back to what it was