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

Free Support Forum - aspose.com

Watermark with Aspose.pdf

Received : 2007/09/27 07:53:29
Message : I've tried to put a watermark behind the text with Aspose.Pdf
But it is printed always over the text.
How could I accomplished this?
I don't mind if it's made with text or image watermark.
Thanks for the attention.


This message was posted using Aspose.Live 2 Forum

Hi,

This is a knows issue and we have logged it. As a workaround please refer to the example code at Send watermark to back.

I’ve tried the workaround, but it doesn’t work.

Text textBorrador = new Text(“Ahórcame”);
textBorrador.TextInfo.FontSize = 75;
textBorrador.RotatingAngle = 45;
textBorrador.TextInfo.Color = new Aspose.Pdf.Color(System.Drawing.Color.LightGray.Name);
textBorrador.TextInfo.RenderingMode = RenderingMode.StrokeText;

Aspose.Pdf.FloatingBox fbWaterMark = new Aspose.Pdf.FloatingBox(400,200);
fbWaterMark.Left = 100;
fbWaterMark.Top = 300;
fbWaterMark.Paragraphs.Add(textBorrador);

Aspose.Pdf.Section sectionPDF = docPDF.Sections[0];
Aspose.Pdf.HeaderFooter oddHeader = sectionPDF.OddHeader;
Aspose.Pdf.HeaderFooter evenHeader = sectionPDF.EvenHeader;

oddHeader.Paragraphs.Add(fbWaterMark);
evenHeader.Paragraphs.Add(fbWaterMark);

If I use docPDF.Sections[0] I don’t see any watermark. If I use docPDF.Sections[1], I see the watermark in the second page.

Thanks for the attention.

Hi,

Can you please send us the complete code including the part where you are creating the pdf.

Thanks.

System.IO.MemoryStream memStreamOrigen = null;

System.IO.MemoryStream memStreamDestino = null;

Aspose.Words.Document docWord = null;

// Open a word file contained in a byte array: bytesFicheroEntrada

memStreamOrigen = new MemoryStream(bytesFicheroEntrada,true);

memStreamDestino = new MemoryStream();

docWord = new Aspose.Words.Document(memStreamOrigen);

// ASPOSE.PDF Conversion

docWord.Save(memStreamDestino,SaveFormat.AsposePdf);

// PDF Conversion

System.IO.MemoryStream pdfStream = new System.IO.MemoryStream();

Aspose.Pdf.Pdf docPDF = new Aspose.Pdf.Pdf();

docPDF.BindXML(memStreamDestino,null);

docPDF.IsImagesInXmlDeleteNeeded = true;

// Watermark try

Text textBorrador = new Text("Ahórcame");

textBorrador.TextInfo.FontSize = 75;

textBorrador.RotatingAngle = 45;

textBorrador.TextInfo.Color = new Aspose.Pdf.Color(System.Drawing.Color.LightGray.Name);

textBorrador.TextInfo.RenderingMode = RenderingMode.StrokeText;

Aspose.Pdf.FloatingBox fbWaterMark = new Aspose.Pdf.FloatingBox(400,200);

fbWaterMark.Left = 100;

fbWaterMark.Top = 300;

fbWaterMark.Paragraphs.Add(textBorrador);

Aspose.Pdf.Section sectionPDF = docPDF.Sections[1];

Aspose.Pdf.HeaderFooter oddHeader = sectionPDF.OddHeader;

Aspose.Pdf.HeaderFooter evenHeader = sectionPDF.EvenHeader;

oddHeader.Paragraphs.Add(fbWaterMark);

// Save pdf to memory

docPDF.Save(pdfStream);

// After this just I create a temp file with this byte array to test the result.

Hi,

Sorry for the inconvenience but we are going to need the word document as well for testing.

Thanks.

No problem. Here you have the word document.

Hi,

I have been able to reproduce this problem. I will discuss this with the developers and we will inform you of a solution as soon as possible.

Thanks.

Hi,

Sorry for my mistake. I checked this issue again and found you can use the example code at Custom Watermark and and the following line:

pdf1.IsWatermarkOnTop = false;

I’ve tried IsWatermarkOnTop = false, but It seems to have the same behaviour.
When I use Sections[0] I don’t see any watermark, and when using Sections[1] the watermark is showed just in the second page.

Can you reproduce the problem?

Thanks again for the attention.

I haven't seen any changes in the newest version of Aspose.pdf

Were you able to reproduce the problem?

I don’t know why your last message is ignored and we have not replied to you. I am terribly sorry for that. I tested with the following code and it works:

//add watermark here
Text textBorrador = new Text(“Ahórcame”);
textBorrador.TextInfo.FontSize = 75;
textBorrador.RotatingAngle = 45;
textBorrador.TextInfo.Color = new Aspose.Pdf.Color(System.Drawing.Color.LightGray.Name);
textBorrador.TextInfo.RenderingMode = RenderingMode.StrokeText;
Aspose.Pdf.FloatingBox fbWaterMark = new Aspose.Pdf.FloatingBox(400,200);
fbWaterMark.Left = 100;
fbWaterMark.Top = 300;
fbWaterMark.Paragraphs.Add(textBorrador);
pdf.Watermarks.Add(fbWaterMark);
pdf.IsWatermarkOnTop = false;

GREAT!

Thanks a lot.