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

Reply via email to