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

Export data form in text file with encoding UTF-8

Community Beginner ,
Dec 10, 2023 Dec 10, 2023

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
1.5K
Translate
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
1 ACCEPTED SOLUTION
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});

 

View solution in original post

Translate
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

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.

Translate
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

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});
Translate
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

Did you look in the JS Reference?

Translate
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

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

Translate
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

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});

 

Translate
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
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.

Translate
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