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

Free Support Forum - aspose.com

Checking existence of watermark

I should be able to check for existence of watermark in a pdf.


I am attaching the code that I am using to create pdf with watermark. (have taken it from the help file provided. I am using version 6.1.0)

Later, I am reading the pdf generated and printing the number of watermarks. It prints 0.

I should be able to check for existence of such watermarks. Please help.

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

Thank you for sharing the sample code.

We have found your mentioned issue after an initial test. Your issue has been registered in our issue tracking system with issue id: PDFNEWNET-31535. We will update your regarding any progress against your issue via this forum thread.

Sorry for the inconvenience caused,

Hi,

In order to get the number of watermark images in document, please try using the following code snippet. In fact in your code snippet, you are passing existing PDF document to Pdf object which is not supported. you can pass MemoryStream object to Pdf but the steam object should be empty.

[C#]
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(@“d:\pdftest\WatermarkExample.pdf”);
//extract the images from PDF
XImageCollection collection = pdfDocument.Pages[1].Resources.Images;
if (collection.Count == 0)
MessageBox.Show(“No Image exists…”);
else
MessageBox.Show(“Number of images in document are :” + collection.Count);

Thanks for the code sample, I am able to identify the presence of images using this code.

However , one of the scenarios where It does not work for me is when, there is already a image present in the pdf.

By identifying watermark image, what I mean is the image that will be repreated through every page. When I am accessing a XImage element from the collection the name property is coming as null.

If I am able to set some unique value here , or some other property in order to be able to uniquely identify the watermark image, that solves the purpose for me.

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

I am afraid this feature is not supported at the moment. I have registered this feature as new feature request in our issue tracking system with issue id: PDFNEWNET-31581. Our development team will further investigate and see if this can be supported in the future version. You will be notified via this forum post regarding any updates against your request.

Sorry for the inconvenience,

Hi Sanjay,


Thanks for your patience. We have been working on resolving this problem so we need some information specific to your requirement. Can you please share that you need to read the watermark count in a PDF file that you are generating using Aspose.Pdf.Generator namespace or you need to read the watermark count from an existing PDF file ?

The issues you have found earlier (filed as 31535) have been fixed in this update.


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

The issues you have found earlier (filed as PDFNEWNET-31581) have been fixed in Aspose.Pdf for .NET 9.3.0.

Blog post for this release can be viewed over this link


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.

Hi Sanjay,


In reference to above PDFNEWNET-31581 fix, to find watermark artifacts in the document, you can use the following code.

Please note that Watermark image is not contained directly in page resources. Watermark is in form resource of the page resources which contains image.Thus you should get (art as WatermarcArtifact).Image in order to get XImage of artifact of XForm in the page resources by its name (art.Form.Name) and find XImage in the resources of this form.

Document doc = new Document(“31581.pdf”);<o:p></o:p>

foreach (Artifact art in doc.Pages[1].Artifacts)

{

if (art is WatermarkArtifact)

{

FileStream fs = new FileStream("artifact_image.png", FileMode.Create, FileAccess.ReadWrite);

//XImage of the artifact

XImage image = (art as WatermarkArtifact).Image;

image.Save(fs, ImageFormat.Png);

fs.Close();

//name of the Form in page resources.

Console.WriteLine("Form name: " + art.Form.Name);

}

}


Please feel free to contact us for any further assistance.


Best Regards,