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?
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});
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.
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});
Copy link to clipboard
Copied
Did you look in the JS Reference?
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
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});
Copy link to clipboard
Copied
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.

