Skip to main content
Skip table of contents

Showing special characters

These examples are written in the context of questions such as:


mathsymbols

JAVA

JAVA
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2023 Apryse Group NV
    Authors: Apryse Software.

    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
package com.itextpdf.samples.sandbox.fonts;

import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

import java.io.File;

public class MathSymbols {
    public static final String DEST = "./target/sandbox/fonts/math_symbols.pdf";

    public static final String FONT = "./src/main/resources/font/FreeSans.ttf";

    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();

        new MathSymbols().manipulatePdf(DEST);
    }

    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);

        PdfFont font = PdfFontFactory.createFont(FONT, PdfEncodings.IDENTITY_H);

        // "Testing math symbols ∈, ∩, ∑, ∫, ∆"
        Paragraph p = new Paragraph("Testing math symbols \u2208, \u2229, \u2211, \u222b, \u2206")
                .setFont(font);

        doc.add(p);
        doc.close();
    }
}

C#

C#
using System;
using System.IO;
using iText.IO.Font;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;


namespace iText.Samples.Sandbox.Fonts
{
    public class MathSymbols
    {
        public static readonly String DEST = "results/sandbox/fonts/math_symbols.pdf";
        
        public static readonly String FONT = "../../../resources/font/FreeSans.ttf";
        
        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();
            
            new MathSymbols().ManipulatePdf(DEST);
        }

        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
            
            PdfFont font = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);
            
            // "Testing math symbols ∈, ∩, ∑, ∫, ∆"
            Paragraph p = new Paragraph("Testing math symbols \u2208, \u2229, \u2211, \u222b, \u2206")
                .SetFont(font);

            doc.Add(p);
            doc.Close();
        }
    }
}


rupeesymbol

JAVA

JAVA
/*
    This file is part of the iText (R) project.
    Copyright (c) 1998-2023 Apryse Group NV
    Authors: Apryse Software.

    For more information, please contact iText Software at this address:
    sales@itextpdf.com
 */
package com.itextpdf.samples.sandbox.fonts;

import com.itextpdf.io.font.PdfEncodings;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.font.PdfFontFactory.EmbeddingStrategy;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Paragraph;

import java.io.File;

public class RupeeSymbol {
    public static final String DEST = "./target/sandbox/fonts/rupee_symbol.pdf";

    public static final String FONT1 = "./src/main/resources/font/PlayfairDisplay-Regular.ttf";
    public static final String FONT2 = "./src/main/resources/font/PT_Sans-Web-Regular.ttf";
    public static final String FONT3 = "./src/main/resources/font/FreeSans.ttf";

    // "The Rupee character ₹ and the Rupee symbol ₨"
    public static final String RUPEE = "The Rupee character \u20B9 and the Rupee symbol \u20A8";

    public static void main(String[] args) throws Exception {
        File file = new File(DEST);
        file.getParentFile().mkdirs();

        new RupeeSymbol().manipulatePdf(DEST);
    }

    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);

        PdfFont font1 = PdfFontFactory.createFont(FONT1, PdfEncodings.IDENTITY_H);
        PdfFont font2 = PdfFontFactory.createFont(FONT2, PdfEncodings.IDENTITY_H);
        PdfFont font3 = PdfFontFactory.createFont(FONT3, PdfEncodings.IDENTITY_H);
        PdfFont font4 = PdfFontFactory.createFont(FONT3, PdfEncodings.WINANSI, EmbeddingStrategy.PREFER_EMBEDDED);

        doc.add(new Paragraph(RUPEE).setFont(font1));
        doc.add(new Paragraph(RUPEE).setFont(font2));
        doc.add(new Paragraph(RUPEE).setFont(font3));
        doc.add(new Paragraph(RUPEE).setFont(font4));

        doc.close();
    }
}

C#

C#
using System;
using System.IO;
using iText.IO.Font;
using iText.Kernel.Font;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;

namespace iText.Samples.Sandbox.Fonts
{
    public class RupeeSymbol
    {
        public static readonly String DEST = "results/sandbox/fonts/rupee_symbol.pdf";

        public static readonly String FONT1 = "../../../resources/font/PlayfairDisplay-Regular.ttf";
        public static readonly String FONT2 = "../../../resources/font/PT_Sans-Web-Regular.ttf";
        public static readonly String FONT3 = "../../../resources/font/FreeSans.ttf";

        // "The Rupee character ₹ and the Rupee symbol ₨"
        public static readonly String RUPEE = "The Rupee character \u20B9 and the Rupee symbol \u20A8";

        public static void Main(String[] args)
        {
            FileInfo file = new FileInfo(DEST);
            file.Directory.Create();

            new RupeeSymbol().ManipulatePdf(DEST);
        }

        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);

            PdfFont font1 = PdfFontFactory.CreateFont(FONT1, PdfEncodings.IDENTITY_H);
            PdfFont font2 = PdfFontFactory.CreateFont(FONT2, PdfEncodings.IDENTITY_H);
            PdfFont font3 = PdfFontFactory.CreateFont(FONT3, PdfEncodings.IDENTITY_H);
            PdfFont font4 = PdfFontFactory.CreateFont(FONT3, PdfEncodings.WINANSI, 
                PdfFontFactory.EmbeddingStrategy.PREFER_EMBEDDED);

            doc.Add(new Paragraph(RUPEE).SetFont(font1));
            doc.Add(new Paragraph(RUPEE).SetFont(font2));
            doc.Add(new Paragraph(RUPEE).SetFont(font3));
            doc.Add(new Paragraph(RUPEE).SetFont(font4));

            doc.Close();
        }
    }
}
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.