Hi Hesham,
you need to know how the font encodes a single character and you have to
use that encoding while creating your string.
E.g. the uppercase "A" is represented by the octal value 0101 (=decimal
65) as character code within the WinAnsiEncoding (just have a look at
the source code of that class). For latin characters you just have to
create a new string at that's it. For non latin charactersets you have
to have a look at the specific font. I guess if you use a window font,
which works fine with word, you have to use a string with a unicode
charset to draw the correct text, e.g.
String yourString = new String("pasted text from word","UTF-8");
I don't know if this really works, but give it a try ...
Andreas Lehmkühler
Hesham G. schrieb:
http://markmail.org/thread/r2bbln57hjng7bxu
Here is an example for a Bulgarian text that appear strange in the PDF :
// Create a new PDF & write some Bulgarian text in it using a Bulgarian font.
try {
PDDocument pdfFile = new PDDocument();
String filePath = "C:\\new_bulgarian.pdf";
PDTrueTypeFont font = PDTrueTypeFont.loadTTF( pdfFile, new File("fonts/bulgarian.ttf") );
//font.setEncoding( new WinAnsiEncoding() );
PDPage page = new PDPage();
PDPageContentStream contentStream = new PDPageContentStream( pdfFile, page );
contentStream.beginText();
contentStream.setFont( font, 10 );
contentStream.moveTextPositionByAmount( 50, 720 );
contentStream.drawString( "??????? ????????" ); // Bulgarian Text.
contentStream.moveTextPositionByAmount( 0, -12 );
contentStream.endText();
contentStream.close();
pdfFile.addPage( page );
pdfFile.save( filePath );
pdfFile.close();
} catch (IOException e) {
e.printStackTrace();
} catch (COSVisitorException e) {
e.printStackTrace();
}
Thanks ,
Hesham