Here's how to reproduce it:
I have to document DocA.pdf and DocB.pdf, where DocA has one page and DocB has two pages.
- Open both documents inside the PDF Editor
- Select the DocA tab so DocA is selected
- I now run my code (see below) that inserts all the pages in DocB (2 pages) at the end of DocA. This works just fine. DocA is still open and now has 3 pages instead of just 1.
- Now I select DocB with its 2 pages. (My goal now is to insert the now 3 pages of DocA into DocB).
- So I run my code below to insert all of the pages in DocA (3 pages now) at the end of DocB. However, instead of inserting all 3 pages of DocA, it only inserts the first page of DocA.
If I perform the same scenario using the PDF Editor's UI (that is, not via code) - Document>>Insert Pages>>Insert Page - It works just fine.
Is there something else I need to do in my code?
Thanks.
--Jeff
Code: Select all
function PDF_InsertPages(ADoc, ASrcDoc: IPXV_Document; ASrcFileName, ASrcPagesAsCommaText: String; ABeforeIndex: Integer; ADeleteSource: Boolean): Boolean;
var
nID: Integer;
pOp: IOperation;
input, options: ICabNode;
APageCount: Cardinal;
begin
Result := False;
if not Assigned(ADoc) then exit;
if not FileExists(ASrcFileName) and not Assigned(ASrcDoc) then exit;
try
ADoc.CoreDoc.Pages.Get_Count(APageCount);
if (ABeforeIndex <= -1) then ABeforeIndex := APageCount; //Append
ABeforeIndex := Max(0, Min(APageCount, ABeforeIndex));
nID := INST_PXV.Str2ID('op.document.insertPages', False);
pOp := INST_PXV.CreateOp(nID);
input := pOp.Params.Root['Input'];
input.v := ADoc;
options := pOp.Params.Root['Options'];
options['Position'].v := ABeforeIndex; //First page
options['Location'].v := 'Before'; //The pages will be inserted before first page
options['CommentsAction'].v := 'Copy'; //Copy all comments
options['FieldsAction'].v := 'Copy'; //Copy all fields
options['BookmarksAction'].v := 'CopyRelated'; //Copy bookmarks that are related to the
if Assigned(ASrcDoc) then
begin
options['Src'].v := ASrcDoc.CoreDoc.SrcInfo.File_;
end else
begin
options['Src'].v := INST_AFS.DefaultFileSys.StringToName(PChar(ASrcFileName), 0, nil);
end;
if (ASrcPagesAsCommaText = '') then
begin
options['PagesRange.Type'].v := 'All';
end else
begin
options['PagesRange.Type'].v := 'Exact';
options['PagesRange.Text'].v := ASrcPagesAsCommaText;
end;
pOp.Do_(0);
if ADeleteSource and Assigned(ASrcDoc) then PDF_DeletePages(ASrcDoc, ASrcPagesAsCommaText);
Result := True;
except
msgbox('Error in PDF_InsertPages');
end;
end;