Skip to content
Advertisement

Using Single Template for all PDF Pages in IText 7

I have the following PDF template which should be consistent for all the pages that gets added in the PDF I am creating ,

enter image description here

The issue is that, am getting this template only for Page 1 and for rest of the pages only blank template is used , Here’s the code am using right now,

JavaScript

I have referred this itextsharp add 1 page template to all pages example already , but I need something specific to Itext 7 since it varies a lot from 5.x.x versions

how do I get my PDF to have the single template as shown in image to be common for all the pages ?

Advertisement

Answer

As explained in the comments, you need to create an IEventHandler as described in chapter 7 of the tutorial

This is an example from the PDF to HTML tutorial (chapter 4).

JavaScript

As you can see, we read the template in the constructor, and we draw it to the Canvas in the handleEvent() method. In this example, we also add a page number in white, you can remove all those lines.

JavaScript

Obviously, you also need to declare the handler:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement