Hi,

It doesn't work with 1.8, but it works with the unreleased 2.0 version, which has a modified API:

PDDocument document = new PDDocument();
        PDPage page1 = new PDPage(PDRectangle.A4);
        document.addPage(page1); // loads font file in the doc
PDFont font = PDType0Font.load(document, new File("/windows/fonts/simhei.ttf")); // Start a new content stream which will "hold" the to be created content PDPageContentStream cos = new PDPageContentStream(document, page1); // Define a text content stream using the selected font, move the cursor and draw some text
        cos.beginText();
cos.setTextMatrix(new Matrix(AffineTransform.getTranslateInstance(200, 200)));
        cos.setFont(font, 12);
        cos.showText("カサタナハ");
        cos.endText(); // close the content stream for page 1
cos.close(); // Save the results and ensure that the document is properly closed:
        document.save("utf8.pdf");
        document.close();


(I don't have the Hiragani font, I tested with the Simhei font, I hope that is ok. But "カサタナハ" did appear. Whatever that means :-) )

See
https://pdfbox.apache.org/downloads.html#scm
https://pdfbox.apache.org/2.0/getting-started.html
https://pdfbox.apache.org/2.0/dependencies.html


Tilman

Am 05.06.2015 um 12:19 schrieb mrunal lohar:
Hi,

I am new to Pdfbox and trying to render 4-byte UTF-8 japanese
characters(e.g. カサタナハ) in pdf file. But Pdf is rendering it incorrectly. I
am pasting my code here:

PDDocument document = new PDDocument();
PDPage page1 = new PDPage(PDPage.PAGE_SIZE_A4);
document.addPage(page1);
// loads font file in the doc
PDFont font = PDTrueTypeFont.loadTTF(document, new File("HIRAGANA.TTF"));
// Start a new content stream which will "hold" the to be created content
PDPageContentStream cos = new PDPageContentStream(document, page1);
// Define a text content stream using the selected font, move the cursor
and draw some text
cos.beginText();
cos.setFont(font, 12);
cos.drawString("カサタナハ"); // HIRAGANA.TTF
cos.endText();
// close the content stream for page 1
cos.close();
// Save the results and ensure that the document is properly closed:
document.save(outputFileName);
document.close();

Please correct me if I am doing something wrong in above code.

Thanks
Mrunal



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to