0

I'm trying to use the Adobe's IAC to save the 1st 2 pages of one document as another. I create an instance of AcroApp like this:

ACROBAT::CAcroAppPtr acApp;
HRESULT hr = acApp.CreateInstance(__uuidof(ACROBAT::AcroApp));

If the creation is successful I open the original PDF like this:

ACROBAT::CAcroPDDocPtr pdDoc;
hr = pdDoc.CreateInstance(__uuidof(ACROBAT::AcroPDDoc));
pdDoc->Open(_bstr_t(L"source.pdf")) // so far so good it has 13 pages

If that is successful I create another PDDoc like this

hr = outDoc.CreateInstance(__uuidof(ACROBAT::AcroPDDoc)); // returns S_OK
outDoc->Create(); // returns -1 which is good

Then I try to add the 1st 2 pages of original document to this new one like this:

pdDoc->InsertPages(0, outDoc, 0, 2, 1); // this returns 0 which means something went wrong

But InsertPages returns error and the new PDDoc still has 0 pages.
What am I missing?
I am using Acrobat Pro 2020 and the original PDDoc has 13 pages in it.
I'm using Visual Studio 2022 for development.

ChrisMM
  • 8,448
  • 13
  • 29
  • 48
Sam
  • 2,473
  • 3
  • 18
  • 29

1 Answers1

0

I found the problem myself.
The 1st parameter of InsertPages is 0 based and for empty document, it should be -1. Than means insert the new pages after the page with index -1. I believe if we want to add pages to the beginning of an existing document, this value should still be -1.
Also I was assuming we have to tell the original document to insert n number of its own pages starting at position x into the newly created document and that is wrong. The correct way is to tell the newly created document to insert n number of pages starting at position of x from the original document. So the correct call would be like:

outDoc->InsertPages(-1, pdDoc, 0, 2, 1);
Sam
  • 2,473
  • 3
  • 18
  • 29