I have overlooked all questions related to this issue on SO, but cant find and answer.
I have a textFile which contains unicode chars like "ā", "š", "ī" and others. The problem is that, when i write textFile to PDF, pdf file do not display it correctly.
How to set up my code, so i could write these chars on my PDF? Maybe even better question is: Is that even possible? Since i have been looking for this for few hours and can't find a solution.
Since this app will be commercial, i 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 someone has done this, pls share how u manage to do taht. I believe it should be related with font.setFontEncoding();
But since PDFBox documentation is lacking quite a lot of information, i havent figured it out, what or how i should do this.
By the way here is the list of SO questions i have read, so pls dont redirect me back to them...
2) Using Java PDFBox library to write Russian PDF
3) Using PDFBox to write UTF-8 encoded strings to a PDF
There was more topic i read, but these was still opened in my tab.
EDITED: Just found this -> Using PDFBox to write unicode strings to a PDF
Seems it's not possbile, need to update to version 2.0.0 and give it a try.
EDITED #2: In new version of PDFBox 2.0.0 (atleast now) has been removed the class TextToPDF()
which let me pass in textFile. So now it means, that either i manually read the text and then write it to PDF, or need to find some other solutions.