What is the fastest way to move pages, within the same document, programmatically?
Manually dragging thumbnails with the mouse, I can reorder several thousand pages instantly. Is there a way to get similar performance with code?
I’ve tried InsertPages, followed by DeletePages.
I've tried this from disk and using an already open doc.
I've tried this from Javascript.
Nothing has even come close.
Please help
Thanks
Move Pages
Moderators: PDF-XChange Support, Daniel - PDF-XChange, Chris - PDF-XChange, Sean - PDF-XChange, Vasyl - PDF-XChange, Ivan - Tracker Software, Stefan - PDF-XChange
-
- Site Admin
- Posts: 3586
- Joined: Thu Jul 08, 2004 10:36 pm
Re: Move Pages
I guess the easiest way is to use JavaScript (see function movePage of Doc object) - here is a simple sample (taken from PDF JS reference) that swaps pages in the document:
And I'm afraid there are no other ways to make it fast and easy.
Code: Select all
for (i = this.numPages - 1; i >= 0; i--) this.movePage(i);
PDF-XChange Co Ltd. (Project Director)
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
When attaching files to any message - please ensure they are archived and posted as a .ZIP, .RAR or .7z format - or they will not be posted - thanks.
-
- User
- Posts: 7
- Joined: Thu Jul 16, 2009 12:31 am
Re: Move Pages
Thanks Ivan,
I’d give up easy for something fast. I think the Javascript movePage would be the easiest way to move a single page but for a range of pages it appears to be the slowest.
Here are some times that I’m seeing using a few different methods:
//Open 7000 page doc from disk
CoPDFXCview1.OpenDocument(Doc_1_LocationOnDisk, '', Doc_1_ID, PXCVA_NoUI);
Elapsed : 00:00:00.162
//insert 7000 pages into open doc from same disk location as open doc
CoPDFXCview1.DoVerb('Documents[0]', 'InsertPages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:24.849
//delete 7000 pages from open doc
CoPDFXCview1.DoVerb('Documents[0]', 'DeletePages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:00.525
//save open doc
CoPDFXCview1.SaveDocument(Doc_1_ID, Doc_1_LocationOnDisk, 0, PXCVA_NoUI);
Elapsed : 00:00:05.044
//CreateNewBlankDocument
CoPDFXCview1.DoVerb('', 'CreateNewBlankDocument', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:00.026
//insert 7000 pages into new blank doc from first open doc
CoPDFXCview1.DoVerb('Documents[1]', 'InsertPages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:33.935
//close new doc
CoPDFXCview1.CloseDocument(Doc_2_ID, PXCVA_NoUI);
Elapsed : 00:00:02.365
//extract 7000 pages from first open doc into new doc
CoPDFXCview1.DoVerb('Documents[0]', 'ExtractPages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:22.374
//close new doc again
CoPDFXCview1.CloseDocument(Doc_2_ID,PXCVA_NoUI);
Elapsed : 00:00:01.094
//move 7000 pages within the open doc using javascript (one at a time)
CoPDFXCview1.RunJavaScript('for (i = 7000; i >= 0; i--) this.movePage(i,5);', ScriptResult, Doc_1_ID, 0);
Elapsed : 00:01:29.993
//load same doc, already open in AX viewer, using pro library
PXCp_ReadDocumentW(MyHPDF, PWChar(WideString(Doc_1_LocationOnDisk)), 0)
Elapsed : 00:00:00.023
//insert 7000 pages from same doc using pro library
PXCp_InsertPagesTo(MyHPDF, MyHPDF, @Range, 1, 0);
Elapsed : 00:00:02.836
//delete 7000 pages using pro library
for i := 0 to 6999 do PXCp_RemovePage(MyHPDF,i);
Elapsed : 00:02:04.268
//save to disk using pro library
PXCp_WriteDocumentW(MyHPDF, PWChar(WideString(Doc_1_LocationOnDisk+'2')), PXCp_CreationDisposition_Overwrite, PXCp_Write_NoRelease)
Elapsed : 00:00:06.100
//OpenDocument in AX viewer that was just written to disk by PXCp_WriteDocumentW
CoPDFXCview1.OpenDocument(Doc_1_LocationOnDisk+'2', '', Doc_2_ID, PXCVA_NoUI);
Elapsed : 00:00:00.145
Clearly, when the user drags thumbnails, the viewer is taking care of this internally with some much faster approach. I'm betting it's just manipulating the order of the page object pointers and not the actual page objects or contents directly.
Is there any chance that such functionality might be exposed through a 'MovePages' operation, in the future?
I’d give up easy for something fast. I think the Javascript movePage would be the easiest way to move a single page but for a range of pages it appears to be the slowest.
Here are some times that I’m seeing using a few different methods:
//Open 7000 page doc from disk
CoPDFXCview1.OpenDocument(Doc_1_LocationOnDisk, '', Doc_1_ID, PXCVA_NoUI);
Elapsed : 00:00:00.162
//insert 7000 pages into open doc from same disk location as open doc
CoPDFXCview1.DoVerb('Documents[0]', 'InsertPages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:24.849
//delete 7000 pages from open doc
CoPDFXCview1.DoVerb('Documents[0]', 'DeletePages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:00.525
//save open doc
CoPDFXCview1.SaveDocument(Doc_1_ID, Doc_1_LocationOnDisk, 0, PXCVA_NoUI);
Elapsed : 00:00:05.044
//CreateNewBlankDocument
CoPDFXCview1.DoVerb('', 'CreateNewBlankDocument', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:00.026
//insert 7000 pages into new blank doc from first open doc
CoPDFXCview1.DoVerb('Documents[1]', 'InsertPages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:33.935
//close new doc
CoPDFXCview1.CloseDocument(Doc_2_ID, PXCVA_NoUI);
Elapsed : 00:00:02.365
//extract 7000 pages from first open doc into new doc
CoPDFXCview1.DoVerb('Documents[0]', 'ExtractPages', '', vDataOut, PXCVA_NoUI);
Elapsed : 00:00:22.374
//close new doc again
CoPDFXCview1.CloseDocument(Doc_2_ID,PXCVA_NoUI);
Elapsed : 00:00:01.094
//move 7000 pages within the open doc using javascript (one at a time)
CoPDFXCview1.RunJavaScript('for (i = 7000; i >= 0; i--) this.movePage(i,5);', ScriptResult, Doc_1_ID, 0);
Elapsed : 00:01:29.993
//load same doc, already open in AX viewer, using pro library
PXCp_ReadDocumentW(MyHPDF, PWChar(WideString(Doc_1_LocationOnDisk)), 0)
Elapsed : 00:00:00.023
//insert 7000 pages from same doc using pro library
PXCp_InsertPagesTo(MyHPDF, MyHPDF, @Range, 1, 0);
Elapsed : 00:00:02.836
//delete 7000 pages using pro library
for i := 0 to 6999 do PXCp_RemovePage(MyHPDF,i);
Elapsed : 00:02:04.268
//save to disk using pro library
PXCp_WriteDocumentW(MyHPDF, PWChar(WideString(Doc_1_LocationOnDisk+'2')), PXCp_CreationDisposition_Overwrite, PXCp_Write_NoRelease)
Elapsed : 00:00:06.100
//OpenDocument in AX viewer that was just written to disk by PXCp_WriteDocumentW
CoPDFXCview1.OpenDocument(Doc_1_LocationOnDisk+'2', '', Doc_2_ID, PXCVA_NoUI);
Elapsed : 00:00:00.145
Clearly, when the user drags thumbnails, the viewer is taking care of this internally with some much faster approach. I'm betting it's just manipulating the order of the page object pointers and not the actual page objects or contents directly.
Is there any chance that such functionality might be exposed through a 'MovePages' operation, in the future?
-
- Site Admin
- Posts: 5223
- Joined: Tue Jun 29, 2004 10:34 am
Re: Move Pages
We are looking into offering this in a forth coming release sometime in June if at all possible.
HTH
HTH
If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.
Best regards
Tracker Support
http://www.tracker-software.com
Best regards
Tracker Support
http://www.tracker-software.com
-
- User
- Posts: 7
- Joined: Thu Jul 16, 2009 12:31 am
Re: Move Pages

-
- Site Admin
- Posts: 5223
- Joined: Tue Jun 29, 2004 10:34 am
Re: Move Pages
Pleasure 

If posting files to this forum - you must archive the files to a ZIP, RAR or 7z file or they will not be uploaded - thank you.
Best regards
Tracker Support
http://www.tracker-software.com
Best regards
Tracker Support
http://www.tracker-software.com
-
- Site Admin
- Posts: 2445
- Joined: Thu Jun 30, 2005 4:11 pm
Re: Move Pages
Hi, millerna.
The new functionality for moving pages inside document has been added into new 2.5.211 build. The example code:
HTH
The new functionality for moving pages inside document has been added into new 2.5.211 build. The example code:
Code: Select all
pdfViewer.SetProperty("Operations.MovePages.RangeType", "Exact"); // supported values: "All", "Odd", "Even", "Exact"
pdfViewer.SetProperty("Operations.MovePages.RangeText", "1-20");
// pdfViewer.SetProperty("Operations.MovePages.RangeFilter", "All"); // supported values: "All", "Odd", "Even"
pdfViewer.SetProperty("Operations.MovePages.InsertBefore", 10); // insert before, zero-based index
pdfViewer.DoDocumentVerb(docID, "", "MovePages", stubObj, null, PXCVA_NoUI);
PDF-XChange Co. LTD (Project Developer)
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
Please archive any files posted to a ZIP, 7z or RAR file or they will be removed and not posted.
-
- User
- Posts: 7
- Joined: Thu Jul 16, 2009 12:31 am
Re: Move Pages
Beautiful!!!
Move 7000 pages using new "MovePages" verb
Elapsed : 00:00:00.087
thats's less than one second!
Thank you. You guys are amazing
Move 7000 pages using new "MovePages" verb
Elapsed : 00:00:00.087
thats's less than one second!
Thank you. You guys are amazing
Last edited by millerna on Wed Jul 17, 2013 10:26 pm, edited 1 time in total.