Java - PDFBox 1.8.9 unicode textfile to pdf -
i have overlooked questions related issue on so, cant find , answer.
i have textfile contains unicode chars "ā", "š", "ī" , others. problem that, when write textfile pdf, pdf file not display correctly.
how set code, write these chars on pdf? maybe better question is: possible? since have been looking few hours , can't find solution.
since app commercial, cant use itext!
my code:
texttopdf pdf = new texttopdf(); string filename = "test.txt"; file pdffile = new file("test.pdf"); bufferedreader reader = new bufferedreader(new filereader(filename)); pdsimplefont courier = pdtype1font.courier; pdsimplefont testfont = pdtruetypefont.loadttf( document, new file("times.ttf" )); pdf.setfont(testfont); pdf.setfontsize(8); pdf.createpdffromtext(document, reader); document.save(pdffile); document.close(); if has done this, pls share how u manage taht. believe should related font.setfontencoding(); since pdfbox documentation lacking quite lot of information, havent figured out, or how should this.
by way here list of questions have read, pls dont redirect me them...
2) using java pdfbox library write russian pdf
3) using pdfbox write utf-8 encoded strings pdf
there more topic read, these still opened in tab.
edited: found -> using pdfbox write unicode strings pdf
seems it's not possbile, need update version 2.0.0 , give try.
edited #2: in new version of pdfbox 2.0.0 (atleast now) has been removed class texttopdf() let me pass in textfile. means, either manually read text , write pdf, or need find other solutions.
your problem here:
bufferedreader reader = new bufferedreader(new filereader(filename)); as described here: http://docs.oracle.com/javase/7/docs/api/java/io/filereader.html filereader read file in system default encoding. change this:
bufferedreader in = new bufferedreader( new inputstreamreader( new fileinputstream(filedir), "utf8")); this read file in utf-8 if in utf-8. special chars described exist in alout of character encoding iso latin 1 etc.
when know encoding of input make sure read in encoding. pdfbox can write them in desired encoding, too.
Comments
Post a Comment