Using SnapshotUtilsEx with link references
Hi,
I hope someone here can explain this to me:
I am trying to add the SnapshotUtilsEx functionality to my InDesign plugin.
This works with the following code:
UIDRef theItem; // this is obtained using ISpread->GetItemsOnPage();
SnapshotUtilsEx *snapshot = new SnapshotUtilsEx(theItem);
ErrorCode drawResult = kFailure;
drawResult = snapshot->Draw();
if (drawResult == kSuccess)
{
IDFile myIDFile; // this is initialized in my plugin
IPMStream *myStream = StreamUtil::CreateFileStreamWriteLazy(myIDFile, kOpenOut);
ErrorCode exportResult = kFailure;
exportResult = snapshot->ExportImageToJPEG(myStream);
myStream->Flush();
myStream->Close();
myStream->Release();
}
if (snapshot != NULL)
{
delete snapshot;
snapshot = NULL;
}
I studied the SDK samples for this and
this works fine, I get the generated thumbnails stored as a file.
Now my question is how can I obtain a UIDRef for the page-item so I can
get the filename from it, because that does not work. I use the following code
to obtain a filename from an image (page-item) UIDRef:
UID link;
// the link UID above is obtained through:
// InterfacePtr<const ILinkManager> linkMgr(documentDB, documentDB->GetRootUID(), UseDefaultIID());
IDataBase *documentDB; // ...
ISession *mySession = GetExecutionContextSession();
InterfacePtr<const ILinkResource> theLinkResource(documentDB, theLink->GetResource(), UseDefaultIID());
InterfacePtr<IK2ServiceRegistry> serviceRegistry(mySession, UseDefaultIID());
InterfacePtr<const IK2ServiceProvider> nameProvider = InterfacePtr<const IK2ServiceProvider>(serviceRegistry->QueryServiceProviderByClassID(kLinkInfoService, kLinkInfoNameProviderBoss));
InterfacePtr<ILinkInfoProvider> nameInfoService = InterfacePtr<ILinkInfoProvider>(nameProvider, UseDefaultIID());
PMString linkImageFileName = nameInfoService->GetUpdatedInfoForLink(theLink, theLinkResource, false);
Obtaining file-names this way throughout my plugin works fine.
For the snapshot I obtain the UIDRef as follows:
UIDRef theItem = kInvalidUIDRef;
InterfacePtr<IDocument> document(database, database->GetRootUID(), IID_IDOCUMENT);
InterfacePtr<ISpreadList> spreads(document, UseDefaultIID());
int32 numberOfSpreads = spreads->GetSpreadCount();
for (int32 i = 0; i != numberOfSpreads; i++)
{
UIDRef spreadUIDRef(database, spreads->GetNthSpreadUID(i));
InterfacePtr<ISpread> spread(spreadUIDRef, UseDefaultIID());
UIDRef theSpread = ::GetUIDRef(spread);
int32 numberOfPages = spread->GetNumPages();
for (int32 j = 0; j != numberOfPages; j++)
{
UID pageUID = spread->GetNthPageUID(j);
UID ownerUID = kInvalidUID;
InterfacePtr<IHierarchy> hierarchy(database, pageUID, UseDefaultIID());
ownerUID = Utils<ILayoutUtils>()->GetOwnerPageUID(hierarchy);
InterfacePtr<IMasterPage> masterPage(database, ownerUID/*pageUID*/, UseDefaultIID());
InterfacePtr<ISpread> masterSpread(database, masterPage->GetMasterSpreadUID(), UseDefaultIID());
masterSpread->GetItemsOnPage(masterPage->GetMasterSpreadPageIndex(), &itemsOnPage, kFalse, kFalse);
numberOfItems = itemsOnPage.Length();
//for (int32 k = 0; k != numberOfItems; k++)
//{
theItem = itemsOnPage.GetRef(/*k*/0);
//}
}
}
I can generate the snapshot just fine with the found UIDRef (theItem), but when trying to get the link-filename
with the code I described above, I get an empty-string.
I tried to walk through the IDocument -> ISpread -> IPage hierarchy and also
the IDocument -> ISpread -> IMasterPage hierarchy.
But clearly I am missing something.
My document has three pages with images on them.
I also followed the instructions found on:
https://community.adobe.com/t5/indesign/getitemsonpage-including-masters/m-p/5878142?page=1
that did not work for me.
Is it possible to get the file-name string from the "theItem" UIDRef?
Why does the UID in theItem differ from the same page-item UID found using ILinkManager?
Thanks in advance.
