pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Maruan Sahyoun <sahy...@fileaffairs.de>
Subject Re: How to Print UTF-8 Characters
Date Wed, 19 Aug 2015 13:15:11 GMT
Hi,

> Am 19.08.2015 um 14:23 schrieb Taiarol, Felipe <felipe.taiarol@sap.com>:
> 
> Hi,
> 
> I am trying to create PDFs in languages such as Chinese and Russian but the characters
of those languages are not being printed correctly.
> 
> This code outputs the attached PDF. 
> 
> I read it has something to do with PDF not supporting UTF-8, I tried to use a font which
had those characters but it didn’t work.


You have to use PDFBox 2.0.0 if you're not already doing so. In addition you need to use a
font which has these characters and load it

PDFont font = PDType0Font.load(doc, new File(path to you ttf file));

Please take a look at the HelloWorldTTF example in the examples project.

BR
Maruan

> 
> String text = "ру́сский язы́к, ру́сский язы́к, ру́сский
язы́к";
> 
> PDDocument document = new PDDocument();
> PDPage page = new PDPage();
> document.addPage(page);
> 
> PDFont font = PDType1Font.HELVETICA_BOLD;
> PDPageContentStream contentStream = new PDPageContentStream( document, page);
> contentStream.beginText();
> contentStream.setFont(font, 12);
> contentStream.moveTextPositionByAmount(100, 700);
> contentStream.drawString(text);
> contentStream.endText();
> contentStream.close();
> 
> document.save("Hello World.pdf");
> document.close();
> Does PDFBox supports printing this type of characters ? How can this be done ?
> 
> Thanks in advance!
> 
> Felipe
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message