2010-11-23 71 views
0
 Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35); 

     BaseFont marathi = iTextSharp.text.pdf.BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1252, BaseFont.EMBEDDED); 

     iTextSharp.text.Font fontNormal = new iTextSharp.text.Font(marathi, 12, iTextSharp.text.Font.NORMAL); 

     PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create)); 
     //Open Document to write 
     doc.Open(); 

     //Write some content 
     Paragraph paragraph = new Paragraph("English मराठी English मराठी English मराठी "); 

     // Now add the above created text using different class object to our pdf document 
     doc.Add(paragraph); 


     doc.Close(); //Close document 

我正在使用上面的代码来生成PDF文件。生成的PDF文件只包含英语单词,不包含मराठी。如何在使用Asp.net/C#和itextsharp生成的pdf文件中嵌入unicode marathi文本?

需要做些什么才能让unicode Marathi字符串包含在pdf中?

回答

0

首先,您需要一个包含所需字符的字体。 “Helvetica”不起作用。然后你需要一个可以表示这些字符的编码。 “身份-H”始终有效。

谷歌的itext字体样本,如果你需要进一步信息。

0

更改了代码,现在它正在工作。 使用Arial Unicode字体。在向段落添加文本的同时,指定要使用的字体。

 Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35); 

     BaseFont marathi = iTextSharp.text.pdf.BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED 

     iTextSharp.text.Font fontNormal = new iTextSharp.text.Font(marathi, 12, iTextSharp.text.Font.NORMAL); 

     PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create)); 
     //Open Document to write 
     doc.Open(); 

     //Write some content 
     Paragraph paragraph = new Paragraph("English मराठी English मराठी English मराठी ", fontNormal); // --->> CHANGED Specify the font to use 

     // Now add the above created text using different class object to our pdf document 
     doc.Add(paragraph); 

     doc.Close(); //Close document 
0
Document doc = new Document(iTextSharp.text.PageSize.LETTER, 10, 10, 42, 35); 

    BaseFont marathi = iTextSharp.text.pdf.BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\ARIALUNI.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED); // --> CHANGED 

    iTextSharp.text.Font fontNormal = new iTextSharp.text.Font(marathi, 12, iTextSharp.text.Font.NORMAL); 

    PdfWriter wri = PdfWriter.GetInstance(doc, new FileStream("c:\\Test11.pdf", FileMode.Create)); 
    //Open Document to write 
    doc.Open(); 

    //Write some content 
    Paragraph paragraph = new Paragraph("English मराठी English मराठी English मराठी ", fontNormal); // --->> CHANGED Specify the font to use 

    // Now add the above created text using different class object to our pdf document 
    doc.Add(paragraph); 

    doc.Close(); //Close document 
+0

如何在上面的段落添加HTML标签 – chandrakat 2011-02-25 07:10:26

相关问题