Hi,

I am trying to write text with Cyrillic characters to a PDF document, I have 1st tried to update the content of fields inside an AcroForm with a Java String containing Cyrillic text, but when I open the PDF document using Acrobat Reader I can see only "????????".

I have created this small program based on some samples, could you please tell me what is wrong (I have tested this with pdfbox 1.4 and 1.6 with the same result)?


public static void main(String args[]) throws IOException, COSVisitorException
{
PDDocument doc = null;

String fontfile = "c:/jms/tmp/arial32/Arial.ttf";
String file = "C:/tmp/test.pdf";
String message = "список мандантов ßäüö"; // The result on the PDF doc is: "??????????????? ßäüö"

try {
doc = new PDDocument();

PDPage page = new PDPage();
doc.addPage(page);
PDFont font = PDTrueTypeFont.loadTTF(doc, fontfile);
//PDFont font = PDType1Font.HELVETICA_BOLD; // I have tested with this font too, and many others

PDPageContentStream contentStream = new PDPageContentStream(
doc, page);
contentStream.beginText();
contentStream.setFont(font, 12);
contentStream.moveTextPositionByAmount(100, 700);
contentStream.drawString(message);
contentStream.endText();
contentStream.close();
doc.save(file);
System.out.println(file + " created!");
} finally {
if (doc != null) {
doc.close();
}
}
}


Thanks in advance,

Jose M. Sánchez

Reply via email to