InsertPages Issue

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
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

InsertPages Issue

Post by jeffp »

I'm experiencing an issue with op.document.insertPages. It is performing one way in code, but correctly if I use your Document>>Insert Pages>>Insert Pages command.

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;
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: InsertPages Issue

Post by Sasha - Tracker Dev Team »

Hello Jeff,

We tried your method with this code and everything worked:

Code: Select all

 //This will insert each file into the beginning of the file
 gInst.PDF_InsertPages( PXV_Control1.Doc, nil, 'z:\Project\Numbers.pdf', '', 0, false);
  gInst.PDF_InsertPages( PXV_Control1.Doc, nil, 'z:\Project\fileInfo.pdf', '', 0, false);
  gInst.PDF_InsertPages( PXV_Control1.Doc, nil, 'z:\Project\356h.pdf', '', 0, false);
  //This will insert each file into the end of the file
 gInst.PDF_InsertPages( PXV_Control1.Doc, nil, 'z:\Project\Numbers.pdf', '', -1, false);
  gInst.PDF_InsertPages( PXV_Control1.Doc, nil, 'z:\Project\fileInfo.pdf', '', -1, false);
  gInst.PDF_InsertPages( PXV_Control1.Doc, nil, 'z:\Project\356h.pdf', '', -1, false);  
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: InsertPages Issue

Post by jeffp »

Please re-read my initial post. That is not the case I described. I'm dealing with two opened documents inside the PDF Editor.

Use ASrcDoc and set ASrcFileName to '';

That is, set ASrc to DocA and ASrcDoc to DocB, two document already opened in the PDF Editor.

The code works fine with ASrcDoc set to nil and ASrcFileName set to a file on disk, as you pointed out. But that's not the case.

Thanks again for looking into this.

FYI: I'm using the 6.0.322.3 build.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: InsertPages Issue

Post by Sasha - Tracker Dev Team »

Hello Jeff,

We found an incorrect usage in your code. This:

Code: Select all

options['Src'].v := ASrcDoc.CoreDoc.SrcInfo.File_;
line of code needs to be changed to

Code: Select all

options['Src'].v := ASrcDoc;
.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
jeffp
User
Posts: 914
Joined: Wed Sep 30, 2009 6:53 pm

Re: InsertPages Issue

Post by jeffp »

Thanks was it. Awesome.

Thanks so much for finding that.

--Jeff
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: InsertPages Issue

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply