How to Get the Selected Content Item

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.
Post Reply
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

How to Get the Selected Content Item

Post by jeffp »

In the Editor with the selection tool on, how can I get the IPXC_ContentItem object associated with the selected content item?

In my case, I want to be able to select an image in the PDF page and then get the associated IPXC_ContentItem object so I can then extract the image to a separate image file. I can do the latter, but I can't figure out how to get the IPXC_ContentItem object of a selected content item.

Thanks.

--Jeff
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to Get the Selected Content Item

Post by Vasyl-Tracker Dev Team »

The pseudocode to enumerate all selected content items:

Code: Select all

IPXV_DocSelection sel;
IPXV_Document doc;
doc.GetSel(Str2ID("selection.contentItems"), out sel);
IPXV_ContentItemsSelection csel = sel;

IPXC_Pages pages = doc.CoreDoc.Pages;

uint iCnt = csel.Count;

for (uint i = 0; i < iCnt; i++)
{
	IPXV_ContentItemEntry pageEntry = csel[i]; // entry.ID - page index
	uint jCnt = pageEntry.Count;
	if (jCnt == 0)
		continue;
	IPXC_Page page = pages[entry.ID];
	IPXC_Content con = page.GetContent(..);
	for (uint j = 0; j < jCnt; j++)
	{
		EnumSelCI(con, pageEntry[j]);
	}
}

void EnumSelCI(IPXC_Content con, IPXV_ContentItemEntry ciEntry)
{
	uint cnt = con.Items.Count;
	if (entry.ID < cnt)
	{
		IPXC_ContentItem selCI = con.Items[entry.ID]; // entry.ID - index of content item inside con.Items[] array
		...
		uint iCnt = ciEntry.Count;
		if ((iCnt != 0) && (selCI.Type == CIT_XForm))
		{
			IPXC_XForm xf = con.Document.GetXFormByHandle(selCI.XForm_Handle);
			if (xf != null)
			{
				IPXC_Content xcon = xf.GetContent(...);
				if (xcon != null)
				{
					for (uint i = 0; i < iCnt; i++)
					{
						EnumSelCI(xcon, ciEntry[i]);
					}
				}
			}
		}
	}
}
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.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: How to Get the Selected Content Item

Post by jeffp »

Ok. I'm able to get the selected ContentItem.

Now I need to create a IIXC_Page from the IPXC_ContentItem, edit it, and then replace it. I can do all but the replacing. How do I swap out the content item's image for a new one?

Step 1:
AItem.Image_CreateIXCPage(False, RI_Perceptual, ixcPage);

Step 2:
ixcPage.Rotate(1); //Rotate 180

Step 3:
How do I replace the old image of Aitem with the edited image?

Thanks.

--Jeff
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to Get the Selected Content Item

Post by Vasyl-Tracker Dev Team »

Here is simple example:

Code: Select all

con = page.GetContent(CAccessMode_WeakClone);
...
con.GetItemForEditing(index, ci);

IPXC_Image curImgObj = ci.Image_Object;
IIXC_Page img = curImgObj.CreateIXCPage();

ChangeImage(img);

IPXC_Image newImgObj = doc.AddImageFromIXCPage(img);
ci.Image_Object = newImgObj;
...

page.PlaceContent(con, PlaceContent_Replace);
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.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: How to Get the Selected Content Item

Post by jeffp »

Ok. I got it working except I have to save the document after I call PlaceContent in order to see the changes to the image in the editor.

Is there some way to call a refresh or something after PlaceContent so that the changes will show without Saving the Document?

--Jeff
User avatar
Vasyl-Tracker Dev Team
Site Admin
Posts: 2352
Joined: Thu Jun 30, 2005 4:11 pm
Location: Canada

Re: How to Get the Selected Content Item

Post by Vasyl-Tracker Dev Team »

With Editor SDK you may use "op.replaceContent", instead of page.PlaceContent():

Code: Select all

op = pxvInst.CreatOp("op.replaceContent");
op.Params["Input"].Add() = coreDoc;
op.Params["Options.NewContent"] = newCon;
op.Params["Options.TargetPage"] = pageIndex;
op.Do();
It is the right way to change the page's content within embedded Editor. It also marks the document 'modified' and adds Undo-item to Undo-history of document.

But if you want just 'silently' update the corresponding page - you may use the IPXV_Document::InvalidatePage.
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.
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: How to Get the Selected Content Item

Post by jeffp »

Perfect! Thanks.
User avatar
TrackerSupp-Daniel
Site Admin
Posts: 8436
Joined: Wed Jan 03, 2018 6:52 pm

How to Get the Selected Content Item

Post by TrackerSupp-Daniel »

:)
Dan McIntyre - Support Technician
Tracker Software Products (Canada) LTD

+++++++++++++++++++++++++++++++++++
Our Web site domain and email address has changed as of 26/10/2023.
https://www.pdf-xchange.com
Support@pdf-xchange.com
Post Reply