'Invalid index in array.' with CoreDoc.GetNamedDestination (PDF 1.1 having /Dests entry in the Catalog)  SOLVED

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
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

'Invalid index in array.' with CoreDoc.GetNamedDestination (PDF 1.1 having /Dests entry in the Catalog)

Post by zarkogajic »

Hi Support,

A sample document:
dest_test_generated.pdf
(17.35 KiB) Downloaded 42 times

I'm trying to read a bookmark's GoTo action (uses a named destination).

IPXC_Action_Goto.IsNamedDest returns true.
IPXC_Action_Goto.DestName returns the correct name of the named destination.

Trying to fill the PXC_Destination from it via IPXC_Document.GetNamedDestination raises an exception: "Invalid index in array."

The "problem" with this specific PDF (attached) is that it has the "old" style (PDF 1.1) "/Dests" entry in the Catalog and does not have the Dests name tree (so no "/Names <</Dests ... >>" in Catalog).

Here's how it looks:

Code: Select all

21 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/Outlines 18 0 R
/PageMode /UseOutlines
/Dests 17 0 R
>>
endobj
And then:

Code: Select all

17 0 obj
<<
/name1 8 0 R
/name2 15 0 R
/name3 16 0 R
>>
endobj
And then, for "name1" for example:

Code: Select all

8 0 obj
[5 0 R /XYZ 33  813.500000  0]
endobj
Is this a bug to be fixed?

Further, the IPXC_Document.GetNameTree("Dests") does return IPXC_NameTree, but Count is 0 (as really there's no "Dests" name tree in the PDF). Should GetNameTree("Dests") return null?

p.s.2
For the moment I can go around the problem by working with IPXS_Document directly and looking for "/Dests" entry in Catalog.


-žarko
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: 'Invalid index in array.' with CoreDoc.GetNamedDestination (PDF 1.1 having /Dests entry in the Catalog)

Post by Ivan - Tracker Software »

I cannot reproduce the issue with your document.

Here is my code (no failure checks to make it simple):

Code: Select all

	HRESULT hr = S_OK;
	do
	{
		hr = InitializeSDK();
		CComPtr<IPXC_Document> pDoc;
		const wchar_t* path = LR"(e:\temp\dest_test_generated.pdf)";
		hr = g_Inst->OpenDocumentFromFile((LPWSTR)path, nullptr, nullptr, 0, 0, &pDoc);
		BreakOnFailure(hr);

		CComPtr<IPXC_Pages> pPages;
		pDoc->get_Pages(&pPages);
		ULONG_T nCnt = 0;
		pPages->get_Count(&nCnt);

		CComPtr<IPXC_Bookmark> bkmRoot;
		CComPtr<IPXC_Bookmark> bkm;
		pDoc->get_BookmarkRoot(&bkmRoot);
		bkmRoot->get_FirstChild(&bkm);
		
		CComPtr<IPXC_ActionsList> actList;
		bkm->get_Actions(&actList);
		CComPtr<IPXC_Action> act;
		actList->get_Item(0, &act);
		CComPtr<IPXC_Action_Goto> actGo;
		act->QueryInterface(&actGo);
		
		CComBSTR destName;
		actGo->get_DestName(&destName);
		PXC_Destination dest;
		hr = pDoc->GetNamedDestination(destName, &dest);
	} while (false);		
It works as expected and fills the dest. I suspect the issue might with a Pascal implementation of BSTR.

In regards GetNameTree("Dests") -- as I see external SDK method does not properly initialize name tree wrapper over PDF 1.1 /Dests dictionary. Will try to fix that, but cannot promise that for the next build.
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: 'Invalid index in array.' with CoreDoc.GetNamedDestination (PDF 1.1 having /Dests entry in the Catalog)

Post by zarkogajic »

Hi Ivan,

Thanks. I'll see to create a sample C# console app to test. Will send if the issue is observed.

Btw, in your code you read Pages and their count - why?

-žarko
User avatar
Ivan - Tracker Software
Site Admin
Posts: 3549
Joined: Thu Jul 08, 2004 10:36 pm
Location: Vancouver Island - Canada
Contact:

Re: 'Invalid index in array.' with CoreDoc.GetNamedDestination (PDF 1.1 having /Dests entry in the Catalog)

Post by Ivan - Tracker Software »

It is just leftovers from another sample
Tracker Software (Project Director)

When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
zarkogajic
User
Posts: 1370
Joined: Thu Sep 05, 2019 12:35 pm

Re: 'Invalid index in array.' with CoreDoc.GetNamedDestination (PDF 1.1 having /Dests entry in the Catalog)  SOLVED

Post by zarkogajic »

Hi Ivan,

Weird. I've now re-run my code ... and it seems all is ok with GetNamedDestination - no exception any more.

Sorry for the false alarm, it must be moth in machines :)



-žarko
Post Reply