We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Extra Page getting created while doing doc to pdf with Watermark

Hi

I am converting a doc to pdf format , also adding a watermark text while converting…

In the Doc there is a table in first page.
But when i add watermark and convert to pdf, the table in the first page gets continued in the second page … (not only tables, it happens for even text)

Any way i can contain the doc2pdf conversion with watermark not produce any extra page?

i have attached code, doc & pdf files

Hi,


You can fix this issue by using the following code:

<pre style=“font-family: “Courier New”; font-size: 9pt;”>private static Document insertWatermarkText(Document doc, String string2) throws Exception {
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);
// Set up the text of the watermark.
watermark.getTextPath().setText(string2);
watermark.getTextPath().setFontFamily(“Times New Roman”);
watermark.setWidth(500);
watermark.setHeight(100);
// Text will be directed from the bottom-left to the top-right corner.
watermark.setRotation(-45);
// Remove the following two lines if you need a solid black text.
watermark.getFill().setColor(Color.lightGray); // Try LightGray to get more Word-style watermark
watermark.setStrokeColor(Color.lightGray); // Try LightGray to get more Word-style watermark
// Place the watermark in the page center.
watermark.setRelativeHorizontalPosition(RelativeHorizontalPosition.PAGE);
watermark.setRelativeVerticalPosition(RelativeVerticalPosition.PAGE);
watermark.setWrapType(WrapType.NONE);
watermark.setVerticalAlignment(VerticalAlignment.CENTER);
watermark.setHorizontalAlignment(HorizontalAlignment.CENTER);
watermark.setName(“WaterMark”);
// Create a new paragraph and append the watermark to this paragraph.
Paragraph watermarkPara = new Paragraph(doc);
watermarkPara.getParagraphBreakFont().setSize(1);
watermarkPara.getParagraphFormat().setSpaceAfter(0);
watermarkPara.getParagraphFormat().setSpaceBefore(0);
watermarkPara.appendChild(watermark);

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

Best regards,