Hi, Unicode doesn't work properly in 1.8. You need to use a pre-release version of PDFBox 2.0, which is available via SVN trunk, or as a SNAPSHOT jar download from our website. Check out the HelloWorldTTF example in 2.0.
P.S. I've CC'd our users mailing list, please ask future questions there. -- John > On 27 Mar 2015, at 04:32, 朱曼 <[email protected]> wrote: > > Dear John, > > When I tried to add Chinese to a PDF file, I get a PDF with strange > characters. I noticed that you have been helped others about this issue > before, for example, on this page, > https://issues.apache.org/jira/browse/PDFBOX-922 > But I am sorry that I am still puzzled about how to do this job. Could you > please help me? Many many thanks! > > Here is the code I am using: > > PDDocument document = new PDDocument(); > PDPage page = new PDPage(); > document.addPage(page); > try { > contentStream = new PDPageContentStream(document, page); > PDFont font = PDTrueTypeFont.loadTTF(document, > "font/f1.ttf"); > > contentStream.beginText(); > contentStream.setFont(font, 30); > contentStream.moveTextPositionByAmount(100, 700); > contentStream.drawString("银行"); > contentStream.endText(); > > contentStream.close(); > document.save("test.pdf"); > document.close(); > } catch (IOException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } catch (COSVisitorException e) { > // TODO Auto-generated catch block > e.printStackTrace(); > } > > Attached please find the font file, and the pdf file generated. > <f1.ttf> > <test.pdf>

