Get icon from one PDF form to another

Adobe Community Professional ,
Mar 27, 2019

Copy link to clipboard

Copied

Hi.

I made a script that import data from one PDF form to another : works fine.

I extend this script to import icons from button fields also : General error - Operation failed

(lines 11 to 13 in the script below)

Since I use an exemple copied from the "JavaScript™ for Acrobat® API Reference" I don't understand where I made a mistake.

Can you help me?

Here is my script (executed from a script embedded within the document) :

// get target document

var docCible = this;

// get source document

var cFileName = "/blablabla/myDoc.pdf";

var docSource = app.openDoc({cPath:cFileName, oDoc:this, bHidden:true});

// list source document fields

for (var i=0; i<docSource.numFields; i++) {

    var oFld = docSource.getField(docSource.getNthFieldName(i));

    // if the field exist in both documents

    if (docCible.getField(oFld.name) != null && docSource.getField(oFld.name) != null) {

        if (oFld.type == "button") {

            // import icon

            docCible.getField(oFld.name).buttonSetIcon(docSource.getField(oFld.name).buttonGetIcon());

        }

        else {

            // import data

            docCible.getField(oFld.name).value = docSource.getField(oFld.name).valueAsString;

        }

    }

}

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

It is a known issue, perhaps something related to security, though it could also be a bug. It simply doesn't work, though it seems like it should, and isn't documented as intentionally not allowed.

TOPICS
Acrobat SDK and JavaScript

Views

367

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Get icon from one PDF form to another

Adobe Community Professional ,
Mar 27, 2019

Copy link to clipboard

Copied

Hi.

I made a script that import data from one PDF form to another : works fine.

I extend this script to import icons from button fields also : General error - Operation failed

(lines 11 to 13 in the script below)

Since I use an exemple copied from the "JavaScript™ for Acrobat® API Reference" I don't understand where I made a mistake.

Can you help me?

Here is my script (executed from a script embedded within the document) :

// get target document

var docCible = this;

// get source document

var cFileName = "/blablabla/myDoc.pdf";

var docSource = app.openDoc({cPath:cFileName, oDoc:this, bHidden:true});

// list source document fields

for (var i=0; i<docSource.numFields; i++) {

    var oFld = docSource.getField(docSource.getNthFieldName(i));

    // if the field exist in both documents

    if (docCible.getField(oFld.name) != null && docSource.getField(oFld.name) != null) {

        if (oFld.type == "button") {

            // import icon

            docCible.getField(oFld.name).buttonSetIcon(docSource.getField(oFld.name).buttonGetIcon());

        }

        else {

            // import data

            docCible.getField(oFld.name).value = docSource.getField(oFld.name).valueAsString;

        }

    }

}

Adobe Community Professional
Correct answer by George_Johnson | Adobe Community Professional

It is a known issue, perhaps something related to security, though it could also be a bug. It simply doesn't work, though it seems like it should, and isn't documented as intentionally not allowed.

TOPICS
Acrobat SDK and JavaScript

Views

368

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Mar 27, 2019 0
Adobe Community Professional ,
Mar 28, 2019

Copy link to clipboard

Copied

Arrgggllll…

I was hoping it would be a known issue.

I tried again: issue is on line 13

Priere.gif

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 28, 2019 0
Most Valuable Participant ,
Mar 28, 2019

Copy link to clipboard

Copied

Is docSource.getField(oFld.name).buttonGetIcon() returning non-NULL?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 28, 2019 0
Adobe Community Professional ,
Mar 29, 2019

Copy link to clipboard

Copied

I will check.

I know that these 2 button fields exist in both documents and there is an icon/image in the source document field, but may be JavaScript can miss that…

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 29, 2019 0
Adobe Community Professional ,
Mar 29, 2019

Copy link to clipboard

Copied

It is a known issue, perhaps something related to security, though it could also be a bug. It simply doesn't work, though it seems like it should, and isn't documented as intentionally not allowed.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 29, 2019 0
Adobe Community Professional ,
Mar 30, 2019

Copy link to clipboard

Copied

Thank you George.

I guess you're right since I also tried as a trusted function and the error remains the same.

Is there another way for importing icons/images from one document to another?

Will importIcon fail too?

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Mar 30, 2019 0
Adobe Community Professional ,
Apr 01, 2019

Copy link to clipboard

Copied

Will importIcon fail too?

Answer is yes.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Apr 01, 2019 0