• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
3

Export data form in text file with encoding UTF-8

Community Beginner ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

I have a pdf form with javascript to export some data in fichier text with the following script :

var Data = 
	this.getField("Texte3").value	
var doc =
	this.createDataObject({cName:"Data.txt",cValue: Data});
	this.exportDataObject({cName:"Data.txt",nLaunch:2});

If there are no special characters in the field, the text file is in UTF-8, but as soon as there is a special character, the text file is in ANSI.

Would there be a solution for the text file to remain in utf-8 but if there are special characters in the field?

TOPICS
PDF forms

Views

273

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
community guidelines

correct answers 1 Correct answer

Community Expert , Dec 10, 2023 Dec 10, 2023

Try this code:

 

var myData = this.getField("Texte3").valueAsString;
var myDataStream = util.streamFromString(myData, "utf-8");
this.createDataObject({cName:"Data.txt",cValue: ""});
this.setDataObjectContents("Data.txt", myDataStream);
this.exportDataObject({cName:"Data.txt", nLaunch:2});

 

Votes

Translate

Translate
Community Expert ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

Use the setDataObjectContents method to populate the file. That way you would be able to specify the encoding directly. There's an example of that in the JS reference for that method.

Votes

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
community guidelines
Community Beginner ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

thank you for your reply
Could you give me an example with the above script?

var Data = 
	this.getField("Texte3").value	
var doc =
	this.createDataObject({cName:"Data.txt",cValue: Data});
	this.exportDataObject({cName:"Data.txt",nLaunch:2});

Votes

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
community guidelines
Community Expert ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

Did you look in the JS Reference?

Votes

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
community guidelines
Community Beginner ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

the JS reference is this: https://www.t10.org/ftp/js_api_reference.pdf?
yes on page 338 but I don't understand their example

Votes

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
community guidelines
Community Expert ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

Try this code:

 

var myData = this.getField("Texte3").valueAsString;
var myDataStream = util.streamFromString(myData, "utf-8");
this.createDataObject({cName:"Data.txt",cValue: ""});
this.setDataObjectContents("Data.txt", myDataStream);
this.exportDataObject({cName:"Data.txt", nLaunch:2});

 

Votes

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
community guidelines
Community Beginner ,
Dec 10, 2023 Dec 10, 2023

Copy link to clipboard

Copied

LATEST

Thank you very much, it works.
Thanks in any case for the example. I don't know how long it would have taken me to achieve this result.
Thanks again.

Votes

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
community guidelines