Skip to main content

This content has been archived and is no longer being updated. Links may not function; however, this content may be relevant to outdated versions of the product.

Support Article

Watermark does not display in PDF

SA-96450

Summary



On adding a water mark to a PDF generated using the HTMLToPDF activity, the watermark does not display on the second page or the watermark image displays multiple times.


Error Messages



Not Applicable


Steps to Reproduce

  1. Create an HTML file.
  2. Create a binary file for the Watermark, url("Webwb/WMR.png");
  3. Add the below code:

    body
    {
    background-repeat:repeat-y !important;
    background-size:100%;
    background-position:right top;
    background-image: url("Webwb/WMR.png");
    background-attachment:fixed;
    }
    inside a style tag -image size (Width: 1139 Height: 747)

     
  4. Run a HTML to PDF activity after adding the HTML file in the activity.


Root Cause



Pega does not provide the out-of-the-box support for watermark in the PDF using the HTMLToPDF activity.


Resolution



Perform the following local-change:  
  1. Open the activity where the HTMLToPDF step is invoked.
  2. Comment the HTMLToPDF step.
  3. Add another step below the HTMLToPDF step.
  4. Use a Java method in the step added in Steps 3 and include the below code in the Java step.

    try{
      String markup = tools.getParamValue("Markup");
      java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
      java.io.StringReader htmlReader = new java.io.StringReader(markup);
      byte[] pdfBytes = null;
      org.zefer.pd4ml.PD4ML pd4ml = new org.zefer.pd4ml.PD4ML();
      pd4ml.setHtmlWidth(1100);
      pd4ml.adjustHtmlWidth();
      
      java.util.Map map = new java.util.HashMap();
      map.put(org.zefer.pd4ml.PD4Constants.PD4ML_EXTRA_RESOURCE_LOADERS, "com.pega.pegarules.integration.engine.internal.mapping.PDFResourceHandler");
      
      //Set WaterMark
      org.zefer.pd4ml.PD4PageMark header = new org.zefer.pd4ml.PD4PageMark();
      header.setWatermark( "https://pd4ml.com/i/logo.png", new java.awt.Rectangle(10,10,300,200), 30);
      pd4ml.setPageHeader(header);
      
      pd4ml.render(htmlReader, baos);
      pdfBytes = baos.toByteArray();
      tools.putParamValue("PDFDocument",pdfBytes);
    } catch (Exception e) {
      e.printStackTrace();
    }

Published January 17, 2020 - Updated December 2, 2021

Was this useful?

100% found this useful

Have a question? Get answers now.

Visit the Collaboration Center to ask questions, engage in discussions, share ideas, and help others.

Did you find this content helpful?

We'd prefer it if you saw us at our best.

Pega Community has detected you are using a browser which may prevent you from experiencing the site as intended. To improve your experience, please update your browser.

Close Deprecation Notice