itext Marathi (indian) language display issue

前端 未结 3 1905
南笙
南笙 2021-01-06 14:03

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 sa

3条回答
  •  醉话见心
    2021-01-06 14:26

    The following worked for me.

    import java.awt.Graphics2D;
    import java.io.*;
    import com.lowagie.text.*;
    
    public class Test { 
        /** Path to the resulting PDF file. */
        public static final String RESULT
        = "/home/test.pdf";
         /**
         * Creates a PDF file: test.pdf
         * @param    args    no arguments needed
         */
        public static void main(String[] args)
            throws DocumentException, IOException {
            Document document = new Document();       
        PdfWriter writer =       
                        PdfWriter.getInstance(document, new FileOutputStream(RESULT));       
        document.open();       
        int w = 400;
        int h = 150;
    
        PdfContentByte cb = writer.getDirectContent();
        PdfTemplate tp = cb.createTemplate(w, h);
        Graphics2D g2 = tp.createGraphicsShapes(w, h);        
        g2.drawString("मराठी ग्रीटींग्स, मराठी शुभेच्छापत्रे", 20, 100);                
        g2.dispose();
        cb.addTemplate(tp, 50, 400);
        document.close();        
    
        }
    }
    

提交回复
热议问题