AFExecuteThisScript Unicode example

Community Beginner ,
Oct 29, 2018

Copy link to clipboard

Copied

Hello,

We are using Acrobat plug-in to save PDF from our application. For one particular scenario we are trying to save a non-english filename (like Chinese, Japanese, Korean, etc) to PDF. We are using AFExecuteThisScript to call the saveAs method to actually save the PDF file.

As per documentation we found here:

ASBool AFExecuteThisScript (PDDoc pdd, const char * cScript, char ** pRetValue)

AcroForm Methods Executes a JavaScript script.

Parameters:

     pdd The PDDoc in which the script is to be executed.

     cScript A string containing the text of the script to be executed. If Unicode, the string must begin with

          0xFEFF and end with 2 null bytes. If this is not the case, it is assumed to be in the application's language

          encoding, as returned by AVAppGetLanguageEncoding.

     pRetValue To get a return value from the execution of the script, pass a non-NULL value for this

          parameter. If on return - pRetVal is non-NULL, the caller should dispose of the string by calling ASFree. If

          present, the value will be in host encoding. NOTE: The script sets this value by assigning it to event.value.

See the Acrobat JavaScript Object Specification for more information.

Return Value:

The JavaScript value of event.rc. This function pre-initializes it to true; a script may set it to false if desired.

Header:

af_sel.h

We tried passing the UTF-8 string from our application and have added to start with 0xFEFF and end with 2 null bytes, but still we are getting the ANSI name PDF filename.

It would be great if an example can be provided for the usage of AFExecuteThisScript() method for non-english characters to be passed to this function.

Thanks,

Amish

TOPICS
Acrobat SDK and JavaScript

Views

213

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

AFExecuteThisScript Unicode example

Community Beginner ,
Oct 29, 2018

Copy link to clipboard

Copied

Hello,

We are using Acrobat plug-in to save PDF from our application. For one particular scenario we are trying to save a non-english filename (like Chinese, Japanese, Korean, etc) to PDF. We are using AFExecuteThisScript to call the saveAs method to actually save the PDF file.

As per documentation we found here:

ASBool AFExecuteThisScript (PDDoc pdd, const char * cScript, char ** pRetValue)

AcroForm Methods Executes a JavaScript script.

Parameters:

     pdd The PDDoc in which the script is to be executed.

     cScript A string containing the text of the script to be executed. If Unicode, the string must begin with

          0xFEFF and end with 2 null bytes. If this is not the case, it is assumed to be in the application's language

          encoding, as returned by AVAppGetLanguageEncoding.

     pRetValue To get a return value from the execution of the script, pass a non-NULL value for this

          parameter. If on return - pRetVal is non-NULL, the caller should dispose of the string by calling ASFree. If

          present, the value will be in host encoding. NOTE: The script sets this value by assigning it to event.value.

See the Acrobat JavaScript Object Specification for more information.

Return Value:

The JavaScript value of event.rc. This function pre-initializes it to true; a script may set it to false if desired.

Header:

af_sel.h

We tried passing the UTF-8 string from our application and have added to start with 0xFEFF and end with 2 null bytes, but still we are getting the ANSI name PDF filename.

It would be great if an example can be provided for the usage of AFExecuteThisScript() method for non-english characters to be passed to this function.

Thanks,

Amish

TOPICS
Acrobat SDK and JavaScript

Views

214

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
Oct 29, 2018 0
Most Valuable Participant ,
Oct 29, 2018

Copy link to clipboard

Copied

It needs to be platform Unicode/WCHAR. That is a form of UTF-16 or UCS2.  Not UTF-8. This is standard Unicode programming EXCEPT for adding the extra BOM (FEFF), so no Acrobat specific example is likely.

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...
Oct 29, 2018 0
Most Valuable Participant ,
Oct 29, 2018

Copy link to clipboard

Copied

Tip: in Windows you can use MultiByteToWideChar. MultiByteToWideChar function | Microsoft Docs

Tip 2: you will probably have a WCHAR array with the Unicode text, and must typecast it for the AFExecuteThisScript method.

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...
Oct 29, 2018 0
Community Beginner ,
Oct 29, 2018

Copy link to clipboard

Copied

Thanks for providing quick tips. Will try it out and will share the findings.

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...
Oct 29, 2018 1
New Here ,
Feb 06, 2020

Copy link to clipboard

Copied

Did you have any luck getting this to work. I'm facing the same issue now.

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...
Feb 06, 2020 0