Extended Latin, Cyrillic and Greek support using code pages

Please note:

The PDF generated by this example will display correctly only in Adobe Acrobat or Reader v7.0 or higher

PDF pdf = new PDF();
Font f1 = new Font(pdf, "MyriadPro-Regular.otf", CodePage.CP1251, Embed.NO);
Font f2 = new Font(pdf, "MyriadPro-Regular.otf", CodePage.CP1252, Embed.NO);
Font f3 = new Font(pdf, "MinionPro-Regular.otf", CodePage.CP1253, Embed.NO);
// Please note:
// All font and image objects must be created before the first page.

Page page = new Page(pdf, Letter.PORTRAIT);
int x_pos = 50;
int y_pos = 0;
TextLine text = new TextLine(f1);
text.setPosition(x_pos, y_pos);
StringBuilder buf = new StringBuilder();
for (int i = 32; i <= 256; i++) {
    if (i % 32 == 0) {
        text.setText(buf.toString());
        text.setPosition(x_pos, y_pos += 24);
        text.drawOn(page);
        buf = new StringBuilder();
    }
    buf.append((char) i);
}
text.setFont(f2);
buf = new StringBuilder();
for (int i = 32; i <= 256; i++) {
    if (i % 32 == 0) {
        text.setText(buf.toString());
        text.setPosition(x_pos, y_pos += 24);
        text.drawOn(page);
        buf = new StringBuilder();
    }
    buf.append((char) i);
}
text.setFont(f3);
buf = new StringBuilder();
for (int i = 32; i <= 256; i++) {
    if (i % 32 == 0) {
        text.setText(buf.toString());
        text.setPosition(x_pos, y_pos += 24);
        text.drawOn(page);
        buf = new StringBuilder();
    }
    buf.append((char) i);
}
pdf.wrap();
pdf.save("Example_06.pdf");
Example_06.java Example_06.pdf

© 2007 Innovatics Inc.