IText用普什图语

时间:2017-04-30 04:52:11

标签: c# pdf unicode itext

我正在使用Itextsharp将数据写入pdf模板。其他Unicode char也没问题。但我们的母语中有八个字符,如(ژ,ړ,څ,ڼ)。当这些字符出现在单词之间时,itextsharp会破坏那里的单词并且这个字符单独写入。我也使用Unicode字体,但没有好结果。下面是我的代码。

public ActionResult GeneratePDF()
        {
            var filename = "~/PdfTemplates/Individual4.pdf";
            string file = Path.Combine(Server.MapPath(filename));

            MemoryStream masterStream = new MemoryStream();

            PdfCopyFields copy = new PdfCopyFields(masterStream);
            PdfReader tmpReader = new PdfReader(file);
            MemoryStream tmpStream = new MemoryStream();
            tmpStream.Position = 0;
        PdfStamper tmpOutStamper = new PdfStamper(tmpReader, tmpStream);
        AcroFields fields = tmpOutStamper.AcroFields;
        var arialFontPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), Server.MapPath("~/fonts/Pashto Nazo.TTF"));
        var arialBaseFont = BaseFont.CreateFont(arialFontPath, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        fields.AddSubstitutionFont(arialBaseFont);
        string tt = "لړم،څپلۍ، کوڼ نړۍ ژمۍ";
       // byte[] utf8Bytes = Encoding.UTF8.GetBytes(tt);

        fields.SetField("TaxPayerName",  tt);


        tmpOutStamper.Writer.CloseStream = false;
        tmpOutStamper.FormFlattening = true;
        tmpOutStamper.Close();
        byte[] buf = tmpStream.ToArray();
        PdfReader nwPgReader = new PdfReader(buf);
        copy.AddDocument(nwPgReader);


       copy.Close();
        byte[] ss = masterStream.ToArray();



        return File(ss, "application/pdf");
    }

及以下是模板的快照 enter image description here

0 个答案:

没有答案