Adding Watermark Resulting into Blank Pages in PDF

Hi Aspose Team,

We are using JDK1.7 and we are using aspose-words-18.6-jdk16.jar in our Java application for generating the PDF out of word document.

In this process, we are adding watermark with text “DRAFT NOT FOR DISTRIBUTION” in generated PDF using our program(PFA).

When we execute the program we can see several blank pages (e.g page 8, 14 etc )added in generated PDF resulting the issue.

In actual word we have only 31 pages but in PDF we can see 41 pages with several blank pages with watermark.

We request you to look into this issue urgently and let us know in case any more details are required from our side.

BlankPageinPreviewPDF.zip (1.1 MB)

Regards,
Jinesh Parikh

@jinesh.parikhmca1983,

Please also ZIP and upload your input Word document (TestPreviewPDF.docx) here for testing. We will then investigate the issue on our end and provide you more information.

Hafeez,

Please find the attached zip containing both sample code, input word document and output PDF document.

Let me know if you need any other detaiils.

Regards,
Jinesh ParikhBlankPageinPreviewPDF.zip (1.1 MB)
TestPreviewPDF.zip (1.8 MB)

@jinesh.parikhmca1983,

You can workaround this problem by adding the following code:

...
...
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.getParagraphFormat().setSpaceBefore(0);
watermarkPara.getParagraphFormat().setSpaceAfter(0);
watermarkPara.getParagraphBreakFont().setSize(1);

watermarkPara.appendChild(watermark);

for (Section sect : doc.getSections())
{
    insertWatermarkIntoHeader(watermarkPara, sect, HeaderFooterType.HEADER_PRIMARY);
...
...

Hafeez,

Apology for the late reply as I was on leave.

The solution provided by you is working fine.

We will try for several documents and will get back to you in case of any issues.

regards,
Jinesh Parikh

@jinesh.parikhmca1983,

Thanks for your feedback. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.