Copier le lien dans le Presse-papiers
Copié
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?
Copier le lien dans le Presse-papiers
Copié
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});
Copier le lien dans le Presse-papiers
Copié
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.
Copier le lien dans le Presse-papiers
Copié
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});
Copier le lien dans le Presse-papiers
Copié
Did you look in the JS Reference?
Copier le lien dans le Presse-papiers
Copié
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
Copier le lien dans le Presse-papiers
Copié
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});
Copier le lien dans le Presse-papiers
Copié
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.
Préparez-vous ! Une expérience Adobe Community améliorée arrive en janvier.
En savoir plus