document images

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, 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.
Post Reply
khho
User
Posts: 34
Joined: Fri Mar 11, 2022 11:02 am

document images

Post by khho »

I want to know if a document contains images (at least one) and I wrote this code.

Code: Select all

			IPXC_Document doc = pdfXChangeCore.OpenDocumentFrom(comStreamWrapper, null);
			if (doc != null)
			{
				for (UInt32 pageIndex = 0; pageIndex < doc.Pages.Count; pageIndex++)
				{
					IPXC_Page page = doc.Pages[pageIndex];
					IPXC_ContentItems items = page.GetContent(PXC_ContentAccessMode.CAccessMode_WeakClone).Items;
					for (UInt32 itemIndex = 0; itemIndex < items.Count; itemIndex++)
					{
						IPXC_ContentItem item = items[itemIndex];
						PXC_CIType itemType = item.Type;

						if ((PXC_CIType.CIT_Image == itemType) || (PXC_CIType.CIT_InlineImage == itemType))
						{
							return true;
						}
					}
				}
			}
			return false;
Do I have to iterate through the pages or is there a short (and quicker) way?
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: document images

Post by Vasyl-Tracker Dev Team »

Hi, khho.

Your method is correct and reliable enough. But incomplete. You also need to look inside XForms:

Code: Select all

...
if (PXC_CIType.CIT_XForm == itemType)
{
      IPXC_XForm xform = doc. GetXFormByHandle(item.XForm_Handle);
      if (xform != null)  
      {
           IPXC_Content xform_con = GetContent(PXC_ContentAccessMode.CAccessMode_Readonly);
           if (xform_con != null)
                  if (RecursiveFindImageInContent(xform_con))
                       return true; 
      }
}
...
Note: for your case is better to use the CAccessMode_Readonly instead of CAccessMode_WeakClone. Because the CAccessMode_Readonly is slightly faster and you don't change the content.

Also there exists another way than can be faster for most docs. Please look there:
viewtopic.php?p=161781#p161781
- here you may find how to enumerate all pdf-objects in doc to handle images. But problem is that method will not 'see' an inline-images and also will see images that aren't on the pages...

HTH.
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.
Post Reply