Support Article
Generated PDF style missing while using PD4ml APIs
SA-46566
Summary
Generated PDF style missing while using PD4ml APIs. When HTMLToPDF activity is used then reported behavior is not seen. However, business requirement is to have different header and footer on each PDF pages.
Error Messages
Not Applicable
Steps to Reproduce
1. Use HTML stream rule having ; and %. Refer below content:
<table width="100%" cellpadding="0" cellspacing="0" border="0" > <tr> <td> <table width="100%" style='table-layout: fixed;font-family:verdana;color:#001400;font-size:16px;width:100%;'> <tr><td width="50%"> </td><td width="50%"> </td></tr> <tr > <th style='font-size:18px;color:#2E92D1;padding:5px;' colspan="2">
2. Pass HTML stream rule to pd4ml API using java step in activity:
try{
HTMLStream = tools.getParamValue("Markup").trim(); ;
org.zefer.pd4ml.PD4ML pd4ml = new org.zefer.pd4ml.PD4ML();
oLog.error("test"+HTMLStream);
org.zefer.pd4ml.PD4Constants PD4Constants = new org.zefer.pd4ml.PD4Constants();
java.awt.Dimension Dimension = new java.awt.Dimension();
java.io.ByteArrayOutputStream os=new java.io.ByteArrayOutputStream();
java.io.InputStream is=new java.io.ByteArrayInputStream(HTMLStream.getBytes());
java.io.InputStreamReader ris=new java.io.InputStreamReader(is);
pd4ml.useTTF("java:fonts", true);
pd4ml.render(ris,os);
byte[] byteArray=os.toByteArray();
tools.putParamValue("PDFDocument",byteArray);
}catch(Exception e){
throw new PRRuntimeException(e.toString());
}
}
Root Cause
The reason why it is working through HTMLtoPDF activity is because pre-processing of stream is happening which removes all these.
The Pega tags will return values after escaping HTML, so semicolon and ampersand are escaped and converted to ,; % characters.
Resolution
Perform the following local-change:
Instead of using Pega tags, use java script like below.
<%
String styleValue = tools.getParamValue("fieldLabelSyl");
String propValue = tools.getProperty("pyCaption").getStringValue();
%>
<td style='<%=styleValue%>'><%=propValue%></td>
(OR)
Replace the special characters as below:
@String.replaceAll(Param.Markup,";",";")
@String.replaceAll(Param.Markup,"%","%")
Published March 26, 2018 - Updated October 8, 2020
Have a question? Get answers now.
Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.