Details
Description
While trying using Chinese Character to write to a PDF, it Displays incorrectly. Sample Code tried .
Also tried with other TTF Files fireflysung.ttf,gbsn00lp.ttf, 金梅毛行书.TTF, SimSun.ttf . Have also tried Modifying the Encoding in PDTrueTypeFont.java loadTTF(PDDocument doc, InputStream stream) method.
PDDocument pdDocument = new PDDocument();
pdDocument.addPage(new PDPage());
BufferedImage bi = new BufferedImage(10, 10, 10);
Points point = new Points(300, 500);
@SuppressWarnings("unchecked")
List<PDPage> list = pdDocument.getDocumentCatalog().getAllPages();
PDPage pdPage = list.get(list.size() - 1);
String fontPathName = "sazanami-gothic.ttf";
PDFont fonta = PDTrueTypeFont.loadTTF(pdDocument,
Sample.class.getClassLoader()
.getResource(fontPathName).openStream() );
PDJpeg ximage = new PDJpeg(pdDocument, bi);
PDPageContentStream contentStream = new PDPageContentStream(pdDocument,
pdPage, true, true);
contentStream.beginText();
contentStream.setFont(fonta,18);
contentStream.moveTextPositionByAmount(point.getX(), point.getY() - 10 );
contentStream.setNonStrokingColor(Color.black);
contentStream.drawString("悲しい");
contentStream.endText();
contentStream.close();
pdDocument.save("test/Test.pdf");
pdDocument.close();
I also looked into other issues reported PDFBOX-1071, PDFBOX-1302 , PDFBOX-491, PDFBOX-696,PDFBOX-725
Attachments
Attachments
Issue Links
- duplicates
-
PDFBOX-922 True type PDFont subclass only supports WinAnsiEncoding (hardcoded!)
- Closed