I have an application that creates a PDF file using Java, Spring and IText.
I want to add a watermark to the pdf.
I have found plenty of examples of adding a watermark to an already saved PDF. I want to add the watermark before the PDF is saved.
I found an example of doing what I want using ITextSharp, however, it is for .NET. I am using the following code in my class that creates the pdf document.
protected void buildPdfDocument(Map model, Document document, PdfWriter writer, HttpServletRequest request,
HttpServletResponse response) throws Exception {
response.setContentType("application/pdf");
ProgramCmd programCmd = (ProgramCmd) request.getSession().getAttribute("programCmd ");
List<Courses> list = programCmd.getCoursesList();
List<Events> eventsList = programCmd.getEventsList();
FONT_SIZE_16_BOLD.setColor(232, 177, 0);
// Print Header
Paragraph paragraph = new Paragraph("Title",FONT_SIZE_16_BOLD);
paragraph.setAlignment(Element.ALIGN_CENTER);
document.add(paragraph);
paragraph = new Paragraph("***This is Not Official***",FONT_SIZE_12_BOLD);
paragraph.setAlignment(Element.ALIGN_CENTER);
document.add(paragraph);
paragraph = new Paragraph("Create Date: " + todaysDate,FONT_SIZE_12_BOLD);
paragraph.setAlignment(Element.ALIGN_CENTER);
document.add(paragraph);
}
Please let me know if you want me to post other code.
Thank you.