Hi i want to create a simple pdf file with spanish characters like: á é í ó ú.
The encoding for the pdf must be WinAnsiEncoding or MacRomanEncoding (Iso-LATIN 1)
The function write() of Ti.Filesystem always creates a file with utf8 encoding regardles of the encoding of the string i use (converted with TI.codec).
If i open the pdf in notepad++ the encoding is always UTF8 and the characters are broken, if i tranform the encoding to ANSI using notrepad++ the pdf file shows the correct characters.
My question is how to force the encoding in the write() function?
In androids java i can use:
OutputStreamWriter osw = new OutputStreamWriter( new FileOutputStream(file), "MacRoman");My code in titanium is:
var doc = require('jspdf_old'); doc.jsPDF(); doc.text(20, 20, 'hello, I am PDF.'); doc.text(20, 30, 'i was created in the browser using javascript.'); doc.text(20, 40, 'o = ó a = á e = é i= í u = ú '); var res; res = doc.output(); var buffer = Ti.createBuffer({ length: 5000 }); var length = Ti.Codec.encodeString({ source: res, dest: buffer, charset: Ti.Codec.CHARSET_ISO_LATIN_1 }); buffer.length = length; var string = Ti.Codec.decodeString({ source: buffer, charset: Ti.Codec.CHARSET_ISO_LATIN_1 }); Ti.API.info(string); if(Ti.Filesystem.isExternalStoragePresent()){ var file = Ti.Filesystem.getFile(Ti.Filesystem.externalStorageDirectory,'test.pdf'); } else { var file = Ti.Filesystem.getFile(Ti.Filesystem.applicationDataDirectory, 'test.pdf'); } file.write(string); if(file.exists) { Ti.API.info('[saveFile] Saved: YES! (' + file.nativePath + ')'); } else { Ti.API.info('[saveFile] Saved: NO!'); }