This document describes how to open a document, delete a page, save and close the document. To delete a page, use kDeletePageCmdBoss.
Issue:
I want to delete a page from my document. How do I do that?
Solution:
If you have an open document, first get the page list (
IPageList, aggregated by
kDocBoss) and then get the
UID of the Page, which you want to delete. Using
IPageList::GetNthPageUID() you could get the page
UID. Then create and process the
kDeletePageCmdBoss by passing the
UID of the page in the item list of the command. The following code snippet describes the step discussed for deleting the first page of the document:
#include "SpreadID.h" // For kDeleteSpreadCmdBoss
ErrorCode status = kFailure;
InterfacePtr<IApplication> myApp(gSession->QueryApplication());
InterfacePtr<IDocumentList> myDocList(myApp->QueryDocumentList());
//Get the first document
IDocument *doc = myDocList->GetNthDoc(0);
if (doc != nil)
{
UID myPageUID;
UIDRef myPageUIDRef;
//Get the page list of the document
InterfacePtr<IPageList> myPageList(doc, UseDefaultIID());
if (myPageList != nil)
{
//Get the UIDRef to the page you want to delete
myPageUID = myPageList->GetNthPageUID(0);
myPageUIDRef = UIDRef(::GetDataBase(doc), myPageUID);
// Create a DeletePageCmd:
InterfacePtr<ICommand> deleteCmd(CmdUtils::CreateCommand(kDeletePageCmdBoss));
if ( deleteCmd != nil )
{
// Set the DeletePageCmd's ItemList:
deleteCmd->SetItemList(UIDList(myPageUIDRef));
// Process the DeletePageCmd:
status = CmdUtils::ProcessCommand(deleteCmd);
}
}
}
else
ASSERT_FAIL("document invalid");
The attached file is the InDesign 2.x code snippet, which shows how to how to open a document, delete a page, save and close the document.