I am evaluating iText as a PDFGenerator for java swing application. The output is supposed to be in "Marathi", which is a local Indian langauge similar to hindi but not same.
For evaluation purposes this is the text i am trying to print:
मराठी ग्रीटींग्स, मराठी शुभेच्छापत्रे
Here is the source code:
package pdftest;
import java.io.FileOutputStream;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Font;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Paragraph;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
public class CPDFTest
{
private static String FILE = "c:/will/FirstPdf.pdf";
public static void main(String[] args)
{
try
{
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(FILE));
document.open();
addMetaData(document);
addTitlePage(document);
document.close();
}
catch (Exception e)
{
}
}
private static void addMetaData(Document document)
{
document.addTitle("My first PDF");
}
private static void addTitlePage(Document document)
throws DocumentException
{
Paragraph preface = new Paragraph();
FontFactory.registerDirectory("C:\\WINDOWS\\Fonts");
Font marFont = FontFactory.getFont("arial unicode ms",BaseFont.IDENTITY_H,true);
// Lets write a big header
preface.add(new Paragraph("मराठी ग्रीटींग्स, मराठी शुभेच्छापत्रे", marFont));
document.add(preface);
}
}
Please check the following image for error details:
I think the issue maybe with the encoding or something but am not able to figure it out as of now. Any help will be appreciated.
Unless included in one of the most recent versions, iText does not support the Devanāgarī writing system.
In some writing systems, there is no one-to-one relation between the actual letter and the correct glyph, but the glyph shape differs depending on e.g. the surrounding glyphs or its position within a word. To render the text correctly, the type setting software needs to implement these rules and AFAIK, iText implements such rules only for Arabic.
The following worked for me.
As itext is not supporting vernacular language,Convert text to bitmap and set as image.Use Below Method for conversion:
Step 1:
Step 2: