![]() Note: Decreasing the opacity of the image prior to using it in the document will improve the aesthetics of the document. Here’s how the book-marked document looks like : PdfWriter pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf")) Next we need to register this event listener with the PdfWriter class. Writer.getDirectContentUnder().addImage(background, width, 0, 0, height, 0, 0) Image background = Image.getInstance("src\\main\\resources\\JavaCodeGeeks-water3.png") Import .PdfPageEventHelper Ĭlass PDFEventListener extends void onEndPage(PdfWriter writer, Document document) This event listener class will listen for the page end event and add the water-mark when it encounters such an event. To add a water-mark to the PDF generated, we shall create a event-listener class. We will see how we can add water-mark to our HelloWorld PDF generated above. When generating PDF documents, many-a-times it is important to add water-mark of your organization or your client’s organization to the document. Once the Document is closed, nothing can be written to the body anymore. When we close the document(line 31), all the elements written to the document get flushed and thus written to the PDF File. Adding an element to the document is enough to get it written to the PDF. Then we add a Paragraph element to the document and indent it to the center. ![]() ![]() Then pass this Documentinstance to the PDFWriter class along-with the FileOutputStream object. Paragraph otherParagraph = new Paragraph() Public static void main(String args) throws FileNotFoundException, DocumentExceptionĭocument document = new pdfWriter = PdfWriter.getInstance(document, new FileOutputStream("HelloWorld.pdf")) We will look at a simple code that will create a PDF with “Hello-World”. We will see in a while how we can achieve this, let’s have a look at the table of contents. The Jar provides implementation of the encryption algorithms we will use, to encrypt the PDF document we generate. We need this Jar for encrypting the PDF Files that we have created. This pom.xml has one more dependency for the bouncycastle.jar.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |