Skip to main content

Support Article

Watermark does not display in PDF



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:

    background-repeat:repeat-y !important;
    background-position:right top;
    background-image: url("Webwb/WMR.png");
    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.


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.

      String markup = tools.getParamValue("Markup"); baos = new; htmlReader = new;
      byte[] pdfBytes = null;
      org.zefer.pd4ml.PD4ML pd4ml = new org.zefer.pd4ml.PD4ML();
      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( "", new java.awt.Rectangle(10,10,300,200), 30);
      pd4ml.render(htmlReader, baos);
      pdfBytes = baos.toByteArray();
    } catch (Exception e) {
Suggest Edit

Published December 10, 2019 - Updated January 16, 2020

Did you find this content helpful?

Have a question? Get answers now.

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

Ready to crush complexity?

Experience the benefits of Pega Community when you log in.

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
Contact us