4 Replies Latest reply on Sep 25, 2010 11:38 PM by cwenet

    merge 2 pdf docs

    cwenet Level 1

      Hi,

       

      with this I want merge 2 pdf files to 1:

       

      // Create a new PDF document:
      var newDoc = app.newDoc();
      // Insert doc1.pdf:
      newDoc.insertPages({
      nPage : -1,
      cPath : "/d/Cover.pdf",

       

      });
      // Insert doc2.pdf:
      newDoc.insertPages({
      nPage : newDoc.numPages,
      cPath : "/d/Book.pdf",

       

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

       

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

       

      The cover.pdf has 2 pages

      The Book.pdf has for example 200 pages.

       

       

      But there is an error:

      TypeError: Ungültiger Argumenttyp.

      ===> Parameter nPage.

       

      What is wrong with the script?

       

      Regards

      Christoph

        • 1. Re: merge 2 pdf docs
          try67 MVP & Adobe Community Professional

          nPage is 0-based, while numPages returns the actual number of pages in the

          file.

          If you want to insert doc2 at the end of the files, use nPage:

          this.numPages-1

          • 2. Re: merge 2 pdf docs
            cwenet Level 1

            Thank you.

            Now, the script looks like this:

             

             

            // Create a new PDF document:
            var newDoc = app.newDoc();
            // Insert doc1.pdf:
            newDoc.insertPages({
            nPage : -1,
            cPath : "/d/Cover.pdf",

             

            });
            // Insert doc2.pdf:
            newDoc.insertPages({
            nPage : newDoc.numPages-1,
            cPath : "/d/Book.pdf",

             

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

             

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

             

            The merging works. But there is one empty page between Cover.pdf and Book.pdf in myNewDoc.pdf.

             

            Do you have an idea, why?

             

            Best regards

            Christoph

            • 3. Re: merge 2 pdf docs
              try67 MVP & Adobe Community Professional

              That's the single, empty page that is created when you execute newDoc(). A

              file must have at least one page.

              You can delete it using deletePages. It's location will be the size of doc1

              + 1.

              1 person found this helpful
              • 4. Re: merge 2 pdf docs
                cwenet Level 1

                Thank you try67,

                 

                for your help. Now it works perfect.

                 

                regards

                 

                Christoph