Check if document has watermark

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
HomerWu
User
Posts: 91
Joined: Fri Nov 25, 2016 8:19 am

Check if document has watermark

Post by HomerWu »

Dear support,

Is there's a way to check a document has watermark when the document opened?
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17960
Joined: Mon Jan 12, 2009 8:07 am
Location: London

Re: Check if document has watermark

Post by Tracker Supp-Stefan »

Hello HomerWu,

The thing is that there is no specific way that a 'watermark' is devined inside a PDF file.
It could be base content that is e.g. rotated so that it appears on the diagonal of a page, and is say 60-80% transparent - however this content is not really distinguishable from other base content in the file, so there is no reliable 'test' for whether something is watermark or not, and as such no way for you to detect that at the time you open a file.

Kind regards,
Stefan
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2353
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: Check if document has watermark

Post by Vasyl-Tracker Dev Team »

Hi, HomerWu.

Stefan is right when we talk about watermarks added in 'dirty' way, directly to the content and without additional info, and therefore - without the proper and reliable way to identify them later.
However, for watermarks added in standard way, via "Add Watermarks" feature in app's UI (in any pdf-app, not just in the Editor) - it is possible to detect the presence of them on the pages:

Code: Select all

PDFXEdit.IPXC_Document coreDoc;
bool bDocHasWatermarks = false;
...

coreDoc.CosDocument.LockDocument();
uint pagesCount = coreDoc.Pages.Count;
for (uint i = 0; i < pagesCount; i++)
{
	PDFXEdit.IPXC_Page page = coreDoc.Pages[i];
	IPXS_PDFVariant pageObj = page.PDFObject;
	IPXS_PDFVariant resObj = pageObj.Dict_Get("Resources");
	if (resObj == null)
		continue;
	IPXS_PDFVariant xoObj = resObj.Dict_Get("XObject");
	if (xoObj == null)
		continue;
	uint xoObjCount = xoObj.Count;
	for (uint j = 0; j < xoObjCount; j++)
	{
		IPXS_PDFVariant it = xoObj[j];
		it = it.Dict_Get("PieceInfo");
		if (it == null)
			break;
		it = it.Dict_Get("ADBE_CompoundType");
		if (it == null)
			break;
		string name = it.Dict_GetName("Private", "");
		if (name == "Watermark")
		{
			bDocHasWatermarks = true;
			break;
		}
	}
	if (bDocHasWatermarks)
		break;	
}

coreDoc.CosDocument.UnlockDocument();
Vasyl Yaremyn
Tracker Software Products
Project Developer

Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.