Question
Accenture
IT
Last activity: 14 Apr 2017 9:20 EDT
Convert PDF to JPG
Hi all,
I need to convert a PDF to JPG as I have got some problems with iframe and modal dialog when at some point of the case I need do display a preview of the PDF.
As a matter of fact, the iframe overlaps always the modal dialog compromising the UX.
A solution could be to convert in some way the PDF to a JPG, to be displayed directly inside its dedicated section with an Icon/Image control.
The questions are
1) Does it exist any OOTB solution?
2) Otherwise, is there a way to solve the problem with iframe overlapping?
Thank you very much.
Regards,
Vincenzo
***Updated by moderator: Lochan to add Categories***
-
Like (0)
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!
Accepted Solution
Pegasystems Inc.
GB
Do you have to use an 'iframe' - or could you use an 'object' / 'embed' style tag instead ?
If you can try 'object' / 'embed' : see here : https://collaborate.pega.com/question/how-display-pdf-sectioninvoice
There is an example of displaying a PDF (and other attachments) in a Modal Window.
I didn't see any issues with the PDF 'bleeding' across the rest of the UI when doing this - I tested with Chrome.
Pegasystems Inc.
GB
Do you have to use an 'iframe' - or could you use an 'object' / 'embed' style tag instead ?
Accepted Solution
Pegasystems Inc.
GB
Do you have to use an 'iframe' - or could you use an 'object' / 'embed' style tag instead ?
If you can try 'object' / 'embed' : see here : https://collaborate.pega.com/question/how-display-pdf-sectioninvoice
There is an example of displaying a PDF (and other attachments) in a Modal Window.
I didn't see any issues with the PDF 'bleeding' across the rest of the UI when doing this - I tested with Chrome.
Accenture
IT
Hi,
thank you for your answer. I am just going to try and see if everything works and then I will let you know the result.
Regards
Accenture
IT
I have found this post, with your previous answer for the same issue.
It was very helpful, thank you very much!
https://collaborate.pega.com/question/custom-pdf-viewer-pega
Accenture
IT
Hi PRITJ, the solution worked for Chrome, but not for IE11.
Have you experienced this kind of issue? Have you got a solution for this?
thank you in advance
Vincenzo
Pegasystems Inc.
GB
@VincenzoP1948 - actually - if you still want to look at the possibility of rendering a PDF to an Image; there is an ('pdfBOX') API to do this; but as it is done on per-page basis - you'll need to work out some details - about how to 'stitch' together multiple pages together into single image.
On PRPC722: the following Java Step will render the first page (page zero) to a PNG file:
@VincenzoP1948 - actually - if you still want to look at the possibility of rendering a PDF to an Image; there is an ('pdfBOX') API to do this; but as it is done on per-page basis - you'll need to work out some details - about how to 'stitch' together multiple pages together into single image.
On PRPC722: the following Java Step will render the first page (page zero) to a PNG file:
byte[] byteArray=(byte[])tools.getParameterPage().getParameterValue("PDFDocument");
String imageName=tools.getParamValue("ImageName");
java.io.ByteArrayInputStream bis=null;
bis = new java.io.ByteArrayInputStream(byteArray);
try {
org.apache.pdfbox.pdmodel.PDDocument doc=org.apache.pdfbox.pdmodel.PDDocument.load( bis );
org.apache.pdfbox.rendering.PDFRenderer pdfRenderer = new org.apache.pdfbox.rendering.PDFRenderer(doc);
java.awt.image.BufferedImage bim = pdfRenderer.renderImageWithDPI(0, 300 , org.apache.pdfbox.rendering.ImageType.RGB); //page 0.
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
javax.imageio.ImageIO.write( bim, "png", baos );
baos.flush();
String result=tools.sendFile(baos.toByteArray(), imageName, false, null, true);
}
catch(Exception e) { throw new PRRuntimeException(e);}
finally {
if (bis!=null) {
try { bis.close(); }
catch(Exception e) { throw new PRRuntimeException(e); }
}
}
This assume two parameters: 'ImageName' (just a String like 'test.png' for instance) and a Java Object - this has to be an ByteArray holding the PDF content.
You test can with running a HTMLTOPDF operation first: then using the 'Pass Current Parameter Page' option when you can the 'wrapper' Activity above.
BTW: If you are not using PRPC722 - you will need to check which version of 'PDBox' is shipped with PRPC.
It appears the library was refactored slightly (it used to be 're-packaged' under a pega package; now it is using the same package name as the original Apache Library).
You can check your system using the following SQL:
select distinct(pzjar) from pr_engineclasses where upper(pzjar) like '%PDF%';
To get the version of the JAR; then you can use something like this to get the package name used:
select distinct(pzpackage) from pr_engineclasses where pzjar='pdfbox-2.0.1.jar'
order by pzpackage;
BTW: the actual implementation of the 'pdfBox' library has also changed between versions; see this StackOverflow post for the difference (I'm using code based on the second version 2.x example).
http://stackoverflow.com/questions/23326562/apache-pdfbox-convert-pdf-to-images
Pegasystems Inc.
GB
Additionally: note you can vary the flags for the 'tools.sendFile' as well: if you need to 'inline' the image within a HTML page, rather than 'save-it' as an 'attachment'. (Change the last flag to 'false' for 'inlining' the image).
Accenture
IT
Thank you, I will try these two solutions and I will let you know.
Thanks again,
Vincenzo