Convert Base 64 to PDF

I have tried using this code in a Java Step before calling Code-Pega-PDF.View Activity.

String s = tools.getParamValue(“Markup”).toString(); //markup is the base64 encoded string

byte[] byteArray = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(s);

tools.putParamValue(“PDFDocument”,byteArray);

I am able to download the PDF file post these steps but I am unable to open the PDF file. Its saying that its damaged (file is not correctly decoded)

Please let me know way to convert Base64 Stream into PDF file.

@SridharP9507 I tried to find documentation and found Use Base64 encoding to send PDF files or images in a SOAP message

Does the activity work if you call it manually?

How do you generate the PDF - is it a link? Are you referring the PDF generation activity in a " Link" control with ‘Harness’ action? If so try in Action Set of Link control add the action ‘Open URL in Window’ with the check box ‘Use Page’ as checked and refer the activity in ‘Activity’ field:

Can you confirm that you followed the steps as outlined in the following forum posts?

Generate pdf using base64 data stream and show it on UI

See solution posted by @Yathender

1: Java

String s = tools.getParamValue("Data").toString();  //Data is the base64 encoded string (Parameter)
byte[] byteArray = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(s);
tools.putParamValue("Data",byteArray);
tools.sendFile(byteArray, "Example.pdf",false, null, false);

This will view pdf in a new window.

if you want to download the file

Step 1: Java

String s = tools.getParamValue("Data").toString();         
byte[] byteArray = new com.pega.pegarules.pub.util.Base64Util().decodeToByteArray(s); 
tools.putParamValue("Data",byteArray);

Step 2: Call Code-Pega-PDF.View

PDFName : Example.pdf

PDFDocument : Param.Data

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

Base64 to PDF

Convert Base64 Stream to PDF

There were some additional steps related to setting section rules and adding your base64 string to some property that you will refer in section rule as mentioned above.

Use HTMLToPDF activity to convert this section rule into a pdf.

Can you lease test using the solution that was provided in the documented which was uploaded by @sandeep.kar07 in the above post?

@MarijeSchillern

When i run activity standalone Pdf getting downloaded. But my scenarios is when i click on button PDF should open in new window which is not happening now.

Could you please elaborate more on below

How do you generate the PDF - is it a link?

Are you referring the PDF generation activity in a " Link" control with ‘Harness’ action?

@MarijeSchillern

Thanks for the given approach. Changed to Action set to Open URL in Window it worked.