Posted: 26 May 2017 8:05 EDT Last activity: 10 Jan 2021 14:30 EST
images not displaying in PDF (generation using PD4ML)
I have a requirement to generate PDF with margins and attach to the case. Used correspondence rules to generates PDF. That correspondence rule having images which are located in"Webwb/". And also the images having visibility conditions (So, for this i created each JPG image as a separate correspondence rule and included those into the main correspondence rule with when rules).
To generate PDF with margins, I used customized PD4ML. When i go with below code, I am getting 2 issues.But, pdf is getting generated with specified margins. Please help me in getting out of this.
1. The images are not at all displaying in generated pdf.
2. The generated pdf is not having any file type (i.e pdf). When i try to view from case attachments the pdf is getting downloaded with no file type.
org.zefer.pd4ml.PD4ML PD4MLObject = new org.zefer.pd4ml.PD4ML();
//Set page size in points (8.5 x 11 inches)
//PD4MLObject.setPageSize( new java.awt.Dimension(595, 842) );
//Set margins in milimeters (top, left, bottom, right)
org.zefer.pd4ml.PD4PageMark footer = new org.zefer.pd4ml.PD4PageMark();
As a test: can you try using the OOTB HTMLTOPDF activity - to convert an HTML file that contains the same image ?
I *believe* that using HTMLTOPDF (or even the lower-level Engine API "PDFUtils pdfUtil=tools.getPDFUtils();") performs the additional task of fetching the static content (including images) from the PRPC store to present to the PD4ML library.
If you use the PD4ML library (again, this is my belief) - this step will not happen and the library will not be able to find the images.
With regard to the image being downloaded with the wrong file extension : you probably need to get the BYTES of the converted PDF and provide this to the 'sendFile' engine API to correct this (which will allow you specify a filename).
What version of PRPC are you using ? Does the HTMLTOPDF activity not provide you with the parameters you need for the borders etc ? (if not; you wish to log a Enhancement Item ("Feedback Item") to see whether this parameters can be included a future version of PRPC : this will not help you in the short-term of course).
We had faced similar challenges with Images in V8.2 as well as V8.5 and we were able to fix plenty of PDF generation issues. Below is the guide.
Purpose: PDF generation using OOTB HTMLToPDF activity – Instructions to retain binary file images, Display Header, Footer, and the Body using Pega OOTB capabilities
HTMLToPDF activity: Use this activity to input below parameters and return param.PDFDocument java object as out parameter, which can be passed as in parameter to the Code-Pega-PDF.View activity to download the PDF.
Param.PDFName Name of the PDF document such as “ABC.pdf”
Param.isCacheClear = true Set this param to true to clear cache used by pd4ml to avoid memory leak with huge TTF & TTC files.
Param.Markup HTML Markup served as body of the HTML. Produce this as out parameter by using activity step methods
Property-Set-Stream over Rule-HTML-Section. Recommendation is to use section rule as auto generated HTML rather than HTML scripting.
Property-Set-HTML step method over Rule-Obj-HTML. This is not the best practice since HTML rules are deprecated in V8.5.1. If you use HTML rules for the markup then expect to see alignment issues in generated PDF each time Pega versions are upgraded.
param.pyPDFFooterHTMLTemplate Set the HTML code to be rendered as a page footer on each page of the PDF. It could be Rule-Obj-HTML based or Rule-HTML-Section based as explained above. Put below HTML inside a table for the footer HTML
Page $[page] of $[total]
param.pyPDFHeaderHTMLTemplate Set the HTML code to be rendered as a page header on each page of the PDF. If your requirement is that the header needs to be displayed only in the first page, then do not define a separate markup, instead add as part of Param.MarkUp HTML.
There are plenty other parameters (related to fonts and font directories, PDF size, orientation etc..) you can study and use as necessary.
Logic to concatenate 2 PDFs:
Generated PDFDocument and PDFDocument1 as out params by calling HTMLToPDF for different markups. Keep below java code before calling View activity.
Since this enhancement needs vetting by the Pega Product Management Team, it is best to push this request through your Account Executive. Product Requests are for issues with the product and it is not a medium to influence the Product Management Team. Your Account Executive might be able to get the timelines for you!
To find out your Pega Account Executive, you could check with the Support Contact inside your organization or call up the Pega Support numbers listed here: Support Contact Information