itext Fonts: iText 5 versus iText 7 (iText 7)


In this iText 7 example, we will create a Hello World example in different languages, using different fonts:

enter image description here

public void createPdf(String dest) throws IOException {
    PdfDocument pdf = new PdfDocument(new PdfWriter(dest));
    try (Document document = new Document(pdf)) {
        PdfFont font = PdfFontFactory.createFont(FontConstants.TIMES_ROMAN);
        PdfFont russian = PdfFontFactory.createFont(
            "CP1251", true);
        PdfFont cjk = PdfFontFactory.createFont(
            PdfEncodings.IDENTITY_H, true);
        Paragraph p = new Paragraph("Hello World! ")
            .add(new Text("Hallo Wereld! ").setFontSize(14))
            .add(new Text("Bonjour le monde! ").setFontSize(10).setTextRise(4))
                new Text("\u0417\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u043b\u0442\u0435 \u043c\u0438\u0440! ")
            .add(new Text("\u4f60\u597d\u4e16\u754c! ")
            .add(new Text("\uc5ec\ubcf4\uc138\uc694 \uc138\uacc4!")

Source: and the iText 7: Building Blocks tutorial.