Discussion

Add Watermark in PDF

Hi,

  • CSS - We can add the watermark image as background image using CSS code. (PDF generated via correspondence rule)

background-image: url("webwb/Watermark.png" );

background-repeat: no-repeat;

background-position: top;

background-size: 100%;

Known issues- When multiple pages are available in the PDF watermark does not display properly. Solution :- we can create small image and can add watermark using background-repeat:repeat-x;

  • PEGA
    • "AddWatermarkToPdfAttachment" – Activity would help achieve adding water mark on Pega 7.3.1
    • However to view this activity, we need to import PDFutils.zip – which we can download online.

https://community1.pega.com/community/product-support/question/how-watermark-generated-pdf-within-pega-version-731

  • Java ITEXT :-

Initially using java Itext code (attached the code) able to add watermark to each page in pdf without any issue however due to licence issue(https://www.lowagie.com/iText) could not integrate the code in Pega.

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.io.FileOutputStream;

import java.io.IOException;

import com.lowagie.text.DocumentException;

import com.lowagie.text.Image;

import com.lowagie.text.pdf.PdfContentByte;

import com.lowagie.text.pdf.PdfReader;

import com.lowagie.text.pdf.PdfStamper;

public class AddWatermark {

public static void main(String[] args) throws IOException, DocumentException {

PdfReader reader = new com.lowagie.text.pdf.PdfReader("Test.pdf");

PdfStamper pdfStamper = new PdfStamper(reader,

new FileOutputStream("TestNew.pdf"));

Image image = Image.getInstance("TestStamp.jpg");

for(int i=1; i<= reader.getNumberOfPages(); i++){

PdfContentByte content = pdfStamper.getUnderContent(i);

image.setAbsolutePosition(10, 50);

content.addImage(image);

}

pdfStamper.close();

}

}

------------------------------------------------------------------------------------------------------------------------------------------------------

Thanks,

Srimathi

Branched Post Information: 

Comments

Keep up to date on this post and subscribe to comments