5 Replies Latest reply on Jan 21, 2013 10:23 PM by SathishVelu

    How to merge two PDF

    SathishVelu

      Hi forum,

       

      This is my first day in learning Javascript for acrobat

       

      I used the tutorial script to merge 2 pdf, but its showing syntax error, please help, i am just a beginner,

       

       

      Below is my code

       

      // Create a new PDF document:

       

      var newDoc = app.newDoc();

       

      // Insert doc1.pdf:

       

      newDoc.insertPages({

       

      nPage : -1,

       

      cPath : "D:\doc1.pdf",

       

      });

       

      // Insert doc2.pdf:

       

      newDoc.insertPages({

       

      nPage : newDoc.numPages,

       

      cPath : "D:\doc2.pdf",

       

      });

       

      // Save the new document:

       

      newDoc.saveAs({

       

      "D:\myNewDoc.pdf");

      });

       

       

       

      This is the error message i get,

       

      "SyntaxError: missing : after property id 29: at line 30"

       

       

      error.jpg

      Thanks in Advance,

       

      Thanks & Regards

      Sathish V.

        • 1. Re: How to merge two PDF
          try67 MVP & Adobe Community Professional

          You're not using correct path syntax.

          To see what is the correct path syntax of a file, open it and then execute

          this code in the JS console:

          this.path

          • 2. Re: How to merge two PDF
            SathishVelu Level 1

            Thanks for your reply,

             

            Here I have pasted the code with correct path

             

            // Create a new PDF document:

             

            var newDoc = app.newDoc();

             

            // Insert doc1.pdf:

             

            newDoc.insertPages({

             

            nPage : -1,

             

            cPath : "/D/doc1.pdf",

             

            });

             

            // Insert doc2.pdf:

             

            newDoc.insertPages({

             

            nPage : newDoc.numPages,

             

            cPath : "/d/doc2.pdf",

             

            });

             

            // Save the new document:

             

            newDoc.saveAs({

             

            "/d/myNewDoc.pdf");

            });

             

            The above coding is taken from AcroJSGuide.pdf file

             

            Still same error message is coming, not working

             

            Thanks

            • 3. Re: How to merge two PDF
              Test Screen Name Most Valuable Participant

              When you use this form for parameters you can list them in order:

               

              method(value1,value2,value3)

               

              When you use this form for parameters you must give them names:

               

              method( { name1:value1 , name2:value2 , name3:value3 } ) ;

               

              The difference is the { }. Notice that in the line with the problem you start out as if it is the second form but end up without a name as if it is the first form. Yes, the example in AcroJSGuide.pdf is wrong.

               

              AcroJSGuide.pdf belongs to Acrobat 7, and is 8 years old. Unless you are forced to develop with this ancient and unsupported version, I recommend you get a more recent Acrobat SDK (which fixes the error too). This is the Acrobat X SDK documents online: http://livedocs.adobe.com/acrobat_sdk/10/Acrobat10_HTMLHelp/wwhelp/wwhimpl/js/html/wwhelp. htm?&accessible=true

              • 4. Re: How to merge two PDF
                try67 MVP & Adobe Community Professional

                Also, there's an extra closing bracket ")" in the last saveAs command, which you need to remove.

                • 5. Re: How to merge two PDF
                  SathishVelu Level 1

                  Thanks for your replies, i finally made it

                   

                  Here is the updated coding to merge 2 pdf using acrobat javascript

                   

                  // Create a new PDF document:

                  var newDoc = app.newDoc();

                  // Insert doc1.pdf:

                  newDoc.insertPages({

                  nPage : -1,

                  cPath : "/d/sathish/1.pdf",

                  });

                  // Insert doc2.pdf:

                  newDoc.insertPages({

                  nPage : newDoc.numPages-1,

                  cPath : "/d/sathish/2.pdf",

                  });

                  // Save the new document:

                  newDoc.saveAs("/d/sathish/myNewDoc.pdf");

                   

                  Thanks & Regards

                  Sathish V.