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