5 Replies Latest reply on Oct 27, 2014 12:01 PM by shawninvancouver

    insertPage RaiseError: An incorrect structure was found in the PDF file

    MikeIs2C Level 1

      Hi,

       

      I am trying to build a button script that will create a new document, copy (insert) from the first page of the open document, save it, then close it.  I believe the part where it gets tricky -- and possibly not doable -- is that the original (source) document uses a template; full of form fields to possibly be spawned off as new pages. 

       

      Given the above, ideally the user of the form can click on the "save new page" button: it creates anj Inserted copy of the first form page, cleared of content if any has been entered, and not including any other pages that may have been spawned. 

       

      With the code I am using, it currently creates the copy of the page and it inserts it as the zeroeth page (ahead of a blank page I intend to add code later to delete) and saves it.  However, there are a couple of problems that come up with this.  First is the error code that opens in the debugger:

       

      RaiseError: An incorrect structure was found in the PDF file

      Doc.insertPages:29:AcroForm:Save New Form:Annot1:MouseUp:Action1

      ===> An incorrect structure was found in the PDF file

       

      Despite the error it does still save the page (form copy) as mentioned above.  However, if you try to start working with it, it lets you know that there are no form fields on the document (even though they are all there and seemingly functional).   When I look to edit the fields, it will then ask you if you want to try to recognize the fields.  If I click on "yes", it says it was unable to, but then the form opens up with all of the field names perfectly matching the original.  If I click on "no" it just opens the page with all of the fields perfectly matching again.  So I feel like I am close to being able to do this!

       

      I am using the following code to produce my results:

       

      (In the JavaScript "app" folder, I have the following trusted functions:)

       

      myTrustedMenu = app.trustedFunction(function(name)

      {

          app.beginPriv();

          app.execMenuItem(name);

          app.endPriv();

      });

       

      myTrustedSaveAs = app.trustedFunction(function(doc, namePath)

      {

          app.beginPriv();

          doc.saveAs(namePath);

          app.endPriv();

      });

       

      myTrustedNewDoc = app.trustedFunction(function()

      {

          app.beginPriv();

          var doc = app.newDoc();

          app.endPriv();

          return doc;

      });

       

      myTrustedInsertPage = app.trustedFunction(function(doc, namePath)

      {

          app.beginPriv();

          doc.insertPages ({

              nPage: -1,

              cPath: namePath,

              nStart: 0

          });

          app.endPriv();

      });

       

      (On the "Save New Form" button, the following code is activated:)

       

      // First split document path into an array

      var aPathComps = this.path.split("/");

       

      // Get File Name off end of array

      var myFileName = aPathComps.pop();

      var pathway = aPathComps.join("/");

       

      var myDoc = myTrustedNewDoc();

       

      myTrustedSaveAs(myDoc, pathway + "/test.pdf");

       

      myTrustedInsertPage(myDoc, this.path);

       

      //myDoc.resetForm();

       

      //myDoc.closeDoc(true);

       

       

      I apologize for the long post and I appreciate anyone who takes the time to look into this issue for me.

       

      Thanks,

       

      Mike

        • 1. Re: insertPage RaiseError: An incorrect structure was found in the PDF file
          mrfale67 Level 2

          Check this out: http://acrobatusers.com/tutorials/file-paths-acrobat-javascript

          Thom wrote another tutorial where one could see how he handles paths. However, I just found the one above now.

           

          Though your error message seems to point to something else, path may also be the cause.

          Please, let us know any progress. Thanks.

          • 2. Re: insertPage RaiseError: An incorrect structure was found in the PDF file
            Test Screen Name Most Valuable Participant

            The reference to "structure" will be about tags. Use the tags view and delete all tags, the problem should go away.

            • 3. Re: insertPage RaiseError: An incorrect structure was found in the PDF file
              MikeIs2C Level 1

              You nailed it TSN!  Deleting the tags did the trick.  Thank you so much for your help!  Just an FYI for any of you fellow "noobs" that might be referencing this discussion, to open the "Tabs" view (in Adobe Acrobat Pro XI in my case) go to View > Show/Hide > Navigation Panels > Tags.  I looked all over the place for that until I found a document that mentioned how to open it.

               

              Anyway, after I deleted the tags as you instructed, I was able to create and save another page as I discussed wanting to do above.  One thing I noticed, however, was that the new document says it needs to be tagged when it is opened.  Should I be concerned about that for any reason or can I just tell the clients to cancel that?

               

              Thanks again for your time and consideration,

               

              Mike 

              • 4. Re: insertPage RaiseError: An incorrect structure was found in the PDF file
                MikeIs2C Level 1

                Hey mrfale67, thank you for your time and consideration in trying to help me with the problems I was experiencing.  Although the answer provided by Test Screen Name was the correct one, I am marking yours as helpful because the path information is a relevant concern for what I am working on here.

                 

                Thanks again and much appreciation goes to people such as yourself and TSN: people who give their time and expertise to try to answer questions like this for people such as myself!

                 

                Mike 

                • 5. Re: insertPage RaiseError: An incorrect structure was found in the PDF file
                  shawninvancouver Level 2

                  MikeIs2C wrote:

                   

                  You nailed it TSN!  Deleting the tags did the trick.  Thank you so much for your help!  Just an FYI for any of you fellow "noobs" that might be referencing this discussion, to open the "Tabs" view (in Adobe Acrobat Pro XI in my case) go to View > Show/Hide > Navigation Panels > Tags.  I looked all over the place for that until I found a document that mentioned how to open it.

                   

                   

                  Thanks for pointing out specifically how to get here. Thanks to the all for this post!

                   

                  I also encountered this error, "An incorrect structure was found in the PDF file" from my published MadCap Flare user guide. I am attempting to find a way to build a bridge between Flare and Google documents for corporate-wide collaboration. Thus far, it's a crazy challenge finding a way to produce gdocs from Flare output. Neither product makes this easy. The closest I can get is by publishing the Flare doc as a PDF... but then I must break that document down into 2mb chucks...which led me to this problem, after attempting to use the Adobe Acrobat splitting tool.

                   

                  Question:

                  What is the root cause of these bad tags. There are a LOT of them! Is this a fault in the way MadCap Flare creates a PDF document?

                   

                  Yes, deleting some of the tags will allow me to finally split a PDF document. Unfortunately, this error occurs in all my published PDF documents, thus preventing me from automating (scripting) this split and then conversion to Google Docs!

                   

                  Thank you