Skip to main content
Skip table of contents

Language-specific examples

Language-specific examples for Arabic and Hindi.


arabicexample

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 com.itextpdf.layout.element.Text;

import java.io.File;

public class ArabicExample {
    public static final String DEST = "./target/sandbox/fonts/arabic_example.pdf";
    public static final String FONT = "./src/main/resources/font/NotoNaskhArabic-Regular.ttf";

    // "السعر الاجمالي"
    public static final String ARABIC = "\u0627\u0644\u0633\u0639\u0631 \u0627\u0644\u0627\u062c\u0645\u0627\u0644\u064a";

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

        new ArabicExample().manipulatePdf(DEST);
    }

    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
        PdfFont f = PdfFontFactory.createFont(FONT, PdfEncodings.IDENTITY_H);

        // It is required to add iText typography dependency to handle correctly arabic text
        Paragraph p = new Paragraph("This is auto detection: ");
        p.add(new Text(ARABIC).setFont(f));
        p.add(new Text(": 50.00 USD"));
        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 ArabicExample
    {
        public static readonly String DEST = "results/sandbox/fonts/arabic_example.pdf";
        public static readonly String FONT = "../../../resources/font/NotoNaskhArabic-Regular.ttf"; 
        
        // السعر الاجمالي 
        public static readonly String ARABIC =
            "\u0627\u0644\u0633\u0639\u0631 \u0627\u0644\u0627\u062c\u0645\u0627\u0644\u064a";

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

            new ArabicExample().ManipulatePdf(DEST);
        }

        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
            PdfFont f = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);

            // It is required to add iText typography dependency to handle correctly arabic text
            Paragraph p = new Paragraph("This is auto detection: ");
            p.Add(new Text(ARABIC).SetFont(f));
            p.Add(new Text(": 50.00 USD"));
            doc.Add(p);

            doc.Close();
        }
    }
}


hindiexample

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.colors.DeviceRgb;
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.Cell;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.element.Table;
import com.itextpdf.layout.properties.UnitValue;

import java.io.File;

public class HindiExample {
    public static final String DEST = "./target/sandbox/fonts/hindi_example.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 HindiExample().manipulatePdf(DEST);
    }

    protected void manipulatePdf(String dest) throws Exception {
        PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
        Document doc = new Document(pdfDoc);
        PdfFont f = PdfFontFactory.createFont(FONT, PdfEncodings.IDENTITY_H);

        // "कार पार्किंग"
        Paragraph p1 = new Paragraph("\u0915\u093e\u0930 \u092a\u093e\u0930\u094d\u0915\u093f\u0902\u0917")
                .setFont(f);
        doc.add(p1);

        // \u0915 क \u093e ा \0930 र
        // \u092a प \u093e ा \u0930 र \u094d ्\u0915 क \u093f \u093f ि \u0902 ं\u0917 ग
        Paragraph p2 = new Paragraph("\\u0915 \u0915 \\u093e \u093e \\0930 \u0930\n"
                + "\\u092a \u092a \\u093e \u093e \\u0930 \u0930 \\u094d \u094d"
                + "\\u0915 \u0915 \\u093f \\u093f \u093f \\u0902 \u0902"
                + "\\u0917 \u0917");
        p2.setFont(f);
        doc.add(p2);

        Table table = new Table(UnitValue.createPercentArray(new float[] {10, 60, 30})).useAllAvailableWidth();
        Cell customerLblCell = new Cell().add(new Paragraph("CUSTOMERS"));
        table.addCell(customerLblCell);

        // "कारपार्किंग"
        p2 = new Paragraph("\u0915\u093e\u0930\u092a\u093e\u0930\u094d\u0915\u093f\u0902\u0917")
                .setFont(f)
                .setFontColor(new DeviceRgb(50, 205, 50));
        Cell balanceLblCell = new Cell().add(p2);
        table.addCell(balanceLblCell);

        table.setMarginTop(10);
        doc.add(table);

        doc.close();
    }
}

C#

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

namespace iText.Samples.Sandbox.Fonts
{
    public class HindiExample
    {
        public static readonly String DEST = "results/sandbox/fonts/hindi_example.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 HindiExample().ManipulatePdf(DEST);
        }

        protected void ManipulatePdf(String dest)
        {
            PdfDocument pdfDoc = new PdfDocument(new PdfWriter(dest));
            Document doc = new Document(pdfDoc);
            PdfFont f = PdfFontFactory.CreateFont(FONT, PdfEncodings.IDENTITY_H);

            // "कार पार्किंग"
            Paragraph p1 = new Paragraph("\u0915\u093e\u0930 \u092a\u093e\u0930\u094d\u0915\u093f\u0902\u0917")
                .SetFont(f);
            doc.Add(p1);

            // \u0915 क \u093e ा \0930 र
            // \u092a प \u093e ा \u0930 र \u094d ्\u0915 क \u093f \u093f ि \u0902 ं\u0917 ग
            Paragraph p2 = new Paragraph("\\u0915 \u0915 \\u093e \u093e \\0930 \u0930\n"
                                         + "\\u092a \u092a \\u093e \u093e \\u0930 \u0930 \\u094d \u094d"
                                         + "\\u0915 \u0915 \\u093f \\u093f \u093f \\u0902 \u0902"
                                         + "\\u0917 \u0917");
            p2.SetFont(f);
            doc.Add(p2);

            Table table = new Table(UnitValue.CreatePercentArray(new float[] {10, 60, 30}))
                .UseAllAvailableWidth();
            Cell customerLblCell = new Cell().Add(new Paragraph("CUSTOMERS"));
            table.AddCell(customerLblCell);
            
            // "कारपार्किंग"
            p2 = new Paragraph("\u0915\u093e\u0930\u092a\u093e\u0930\u094d\u0915\u093f\u0902\u0917")
                .SetFont(f)
                .SetFontColor(new DeviceRgb(50, 205, 50));
            Cell balanceLblCell = new Cell().Add(p2);
            table.AddCell(balanceLblCell);
            
            table.SetMarginTop(10);
            doc.Add(table);

            doc.Close();
        }
    }
}

Resources

 

JavaScript errors detected

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

If this problem persists, please contact our support.