Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Why do I have to run a doc.saveAs() prior to Inserting, Deleteing, or Extracting pages?

Avatar

Former Community Member

MY SETUP:

I'm using folder level javascripts.   In Acrobat I have the 'enable menue items javascript execution privledge' enabled,  In my actual folder level scrips I have them wrapped in a trusted function along with app.beginPriv()/app.endPriv().    My PDF's are coming from LiveCycle Designer which I then open and run in Acrobat.

MY QUESTION:

Through much trial and error and banging my head on the wall I've found that if I want to use insertPages(), extractPages() or deletePages() called as a trusted fucntion  on its own it won't work unless I first run a saveAs() function to create a new document file and only then can I run the desired function on the new saveAs'd doc.   I simply can't run an insertPages() on the current open doc without a saveAs first().    

Why is that?

I find that very frusterating and the resulting errors aren't a help.  If I don't SaveAs first I get security error or invalid function errors.

EXAMPLE:

Save As Function:

var LCB_SaveAs = app.trustedFunction(function(doc, filename) {

    app.beginPriv();

    doc.saveAs(filename);

    app.endPriv();

});

Insert Page Function:

var TEST_InsertPage = app.trustedFunction(function(doc, filename) {

    app.beginPriv();

       doc.insertPages ({

           nPage: -1,

           cPath: filename

       });

       app.endPriv();

});

Javascript code in document to call the above functions:

if(typeof(LCB_SaveAs) == "function") {

    if(typeof(TEST_InsertPage) == "function") {

        try {

            TempFileLocation = "/C/PATH/InsertTemp.pdf"

            LCB_SaveAs(event.target, TempFileLocation);

            try {

                PathOfInsertDoc = "/C/PATH/FileToInsertIntoSaveAs'dDoc.pdf"

                TEST_InsertPage(event.target, PathOfInsertDoc)

            }

            catch(e) {

                xfa.host.messageBox(e.toString().replace("RaiseError: ","") , 0, 0); 

            }

        }

        catch(e) {

            xfa.host.messageBox(e.toString().replace("RaiseError: ",""), 0, 0); 

        }

    }

}

2 Replies

Avatar

Level 6

Interesting. These are static XFA Foreground forms, correct? As a test, what happens if you attempt to extract a page via the JavaScript console?

Avatar

Former Community Member

Hi George.  Yes I'm using static XFA forms which were created with PDF's as basic 'artwork' in the background and then my custom fields and script tunning on top. 

I've tried running  a function (below) in the console, but did nothing -- maybe a syntack error.  I don't know what that may or may not mean though.  I'm not use to running stuff through the console so I could be doing it wrong.  My console experiance is limited to calling the path where the javascripts folder resides.

Attempt script in console:

var MJS_HN_Delete_RevisitForm = app.trustedFunction(function(doc) {

    app.beginPriv();

    doc.deletePages(15, 15);

    app.endPriv();

});

and/or this:

app.trustedFunction(function(doc) {

    app.beginPriv();

    doc.deletePages(15, 15);

    app.endPriv();

});