Question

pdf generated from htmltopdf ootb activity needs to be converted to binary stream

HI, I generated a pdf using htmltopdf activity and the output of the activity (byte array ) is something like-

b[4dhcudh , the pdf looks fine using ootb activity - View .

but my requirement is to convert this format pdf to binary stream so that I can store as Data-WorkAttach-File instance and also send to an api .

Please suggest few steps for conversion.

Comments

Keep up to date on this post and subscribe to comments

June 6, 2018 - 2:38pm

Not sure if i completely understand your requirement.  htmptopdf will generate a byte array and isn't that the byte array something you can use to send to api etc?

 

//Get the PDF generation utility class
PDFUtils pdfUtil=tools.getPDFUtils();

//BUG- 32651 Back-Ported HFix-2932
//Get the PDF bytes.
byte[] byteArray = pdfUtil.generatePDF(HTMLStream,tools.getParameterPage());

if (byteArray == null || byteArray.length == 0)
{
    oLog.error("PDFUtils did not return any content for HTMLtoPDF");
}
else
{
    //Put the byte array in a parameter
    tools.putParamValue("PDFDocument",byteArray);
}

June 7, 2018 - 1:45am
Response to WaikeiKwok_GCS

HI  WaikeiKwok_GCS,

Thanks for your reply,

what I understood from this code is the final outcome in PDFDocument is still a  byte array .
If not can you please make me understand what the first line of code i.e. byte[] byteArray = pdfUtil.generatePDF(HTMLStream,tools.getParameterPage()); is doing.
also this code is not getting compiled
ERROR- —
Java at step: 4 line: 6
HTMLStream cannot be resolved to a variable

July 16, 2018 - 6:45am
Response to divyad71

it may helps you.

First call HTMLTOPDF where you will receive PDFDocument  as the outpur parameter in form of bytes.

Than The function  Byte2Base64Encoded will take the byte array as input and convert it into the binary stream.

set param.attachStream=@(COFW:LabLib).Byte2Base64Encoded(tools) will give u the binary stream.

 

June 6, 2018 - 11:36pm

you can try call AttachToWork from page PDF (Code-Pega-PDF)

after calling htmltopdf if you need to attach it to work .

Pega
July 24, 2018 - 8:16am

What do you need? A binary stream (something that is derived from java.io.InputStream)?

In that case, you wrap the result from pdfUtil.generatePDF() into an instance of java.io.ByteArrayInputStream.

Pega usually stores binary data in Strings, and as binary data may contain binary values that are not allowed inside a String, you cannot use new String() with the result from pdfUtil.generatePDF() as argument; instead you need to convert that output into BASE64 first; for that conversion you have several options. The outcome is now a Java String that can be put to text properties on the Clipboard.

So please check what you really needs; what type the target property has, or what type is requested on the signature of the function you want to use.