Free Support Forum - aspose.com

PDF watermark

Hi there


I’m using Aspose.word for Java. I took watermark example Aspose.Words.Java.Samples\AddWatermark, and it worked fine with MS Word, but with pdf nothing happened and there is no watermark in exported pdf.

docName = docName + “.pdf”;
tempName = tempName + “.pdf”;
PdfOptions options = new PdfOptions();
options.setHeadingsOutlineLevels(3);
options.setExpandedOutlineLevels(1);
insertWatermarkText(doc, “UNCONTROLLED WHEN PRINTED”);
doc.saveToPdf(0, doc.getPageCount(), dir + tempName, options);

Do you have any idea what the problem is?

Cheers
Alireza

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Could you please attach your document here for testing? I will check the problem on my side and provide you more information.

Best regards,

Hi there


Do you mean document that I’m trying to export? If yes, please find attached documents. I attached a MS Word (successfully add watermark) and a PDF file (with no watermark), both generated and exported with almost the same code. I’m creating it out of a html document.

if (type.equalsIgnoreCase(“MsWord”)) {
response.setContentType(“application/msword”);
docName = docName + “.doc”;
tempName = tempName + “.doc”;
insertWatermarkText(doc, “uncontrolled when printed”);
doc.save(dir + tempName);
} else if (type.equalsIgnoreCase(“pdf”)) {
response.setContentType(“application/pdf”);
docName = docName + “.pdf”;
tempName = tempName + “.pdf”;
PdfOptions options = new PdfOptions();
options.setHeadingsOutlineLevels(3);
options.setExpandedOutlineLevels(1);
insertWatermarkText(doc, “UNCONTROLLED WHEN PRINTED”);
doc.saveToPdf(0, doc.getPageCount(), dir + tempName, options);
}

.
.
.
.
private static void insertWatermarkText(com.aspose.words.Document doc, String watermarkText) throws Exception
{
// Create a watermark shape. This will be a WordArt shape.
// You are free to try other shape types as watermarks.
Shape watermark = new Shape(doc, ShapeType.TEXT_PLAIN_TEXT);

// Set up the text of the watermark.
watermark.getTextPath().setText(watermarkText);
watermark.getTextPath().setFontFamily(“Arial”);
watermark.setWidth(120);
watermark.setHeight(500);
// 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.GRAY); // Try LightGray to get more Word-style watermark
watermark.setStrokeColor(Color.GRAY); // 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);
.
.
.
.
.

Cheers
Alireza

Hello<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. The problem occurs because Aspose.Words for Java does not support WordArt during converting to PDF. WordArt is already supported in .NET version of Aspose.Words. Currently we are working on synchronizing .NET and Java versions of Aspose.Words. Once we finish this work, this feature will be available in Java versions.

As a temporary workaround, you can try inserted an image as a watermark.

Also I think information provided in this thread will be useful for you:

Best regards,

The issues you have found earlier (filed as WORDSJAVA-35) have been fixed in this .NET update and in this Java update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(5)