5 Replies Latest reply on Jun 7, 2011 6:42 AM by cwenet

    extractpages (bookmarkes gone)

    cwenet

      Hi,

       

      I want to extract page ranges in several files.

       

      This works good:

       

      function split1()
      {

       

      this.extractPages({
      nStart: 2,
      nEnd: 10,
      cPath: "test_1.pdf"
      });

       

      this.extractPages({
      nStart: 11,
      nEnd: 80,
      cPath: "test_2.pdf"
      });

       

      }
      app.addMenuItem({ cName: "split", 
            cParent: "Edit", 
            cExec: "split1()",
            nPos: 1});

       

      But the bookmarks are gone in the result files test_1.pdf, test_2.pdf.

      How can I keep the bookmarks from the sourcefile?

       

      Best Regards

      Christoph

        • 1. Re: extractpages (bookmarkes gone)
          Bernd Alheit Adobe Community Professional & MVP

          Copy the sourcefile and delete the unwanted pages.

          • 2. Re: extractpages (bookmarkes gone)
            cwenet Level 1

            Hi Bernd,

             

            Thank you. I tried this:

             

            var newDoc = app.newDoc();

            // Insert doc1.pdf:
            newDoc.insertPages({
            nPage : -1,
            cPath : "/c/doc1.pdf"
            });

             

            newDoc.deletePages({nStart: 2, nEnd: 5});

             


            // Save the new document:
            newDoc.saveAs("/c/myNewDoc.pdf");

             

            // Close the new document without notifying the user:
            newDoc.closeDoc(true);

             

            But there is an empty page after the last page.

            And the bookmarks are gone again.

            And an error: UnsupportedValueError:  ===> Parameter cPath.

             

            Please, do you can help again?

             

            Christoph

            • 3. Re: extractpages (bookmarkes gone)
              try67 MVP & Adobe Community Professional

              insertPages is no different to extractPages in this sense. Both will cause

              the bookmarks to be lost.

              What Bernd suggested is that you save a copy of the original file under the

              new file name, then open that copy and delete the pages you don't want to

              have in the new file. That way the bookmarks will be preserved.

              • 4. Re: extractpages (bookmarkes gone)
                cwenet Level 1

                Thank you try67,

                 

                now my code looks like this:

                 

                this.saveAs("/d/in/copy.pdf");


                var otherDoc = app.openDoc("/d/in/copy.pdf");
                otherDoc.deletePages(0,19);
                otherDoc.deletePages(13,131);
                otherDoc.saveAs("/d/in/myNewDoc2.pdf");
                otherDoc.closeDoc(true);

                 

                It works fine and the bookmarks are save.

                 

                With this code I extract the pages 21 to 33 from a doc with 152 pages.

                I tried a long time.

                 

                Do you know a math formula to get page range for example 21 to 33?

                The totalpage is also known with "this.numPages".

                 

                Best regards

                Christoph

                • 5. Re: extractpages (bookmarkes gone)
                  cwenet Level 1

                  Hi,

                   

                  now I have a few code lines that works for me:

                   

                  if (split[i][1] == count) {

                   

                  otherDoc.deletePages(0,split[i][0]-2);
                  }else{
                              if (teilen[i][0] == 1) {
                              otherDoc.deletePages(split[i][1],count-1);
                              }else{
                  otherDoc.deletePages(split[i][1],count-1);
                  otherDoc.deletePages(0,split[i][0]-2);
                                          }
                              }

                   

                  Perhaps a little complicated, but it works.

                   

                  Christoph