小编Kia*_*sos的帖子

通过ITextSharp从persian html文件创建pdf

我使用ITextSharp库将html转换为pdf.我的用户在她/他的html文件中使用波斯语句,所以这个库不能转换波斯语.

为解决此问题和从右到左的问题,我使用以下代码:

        Document document = new Document(PageSize.A4, 80, 50, 30, 65);
        PdfWriter.GetInstance(document, new FileStream(strPDFpath, FileMode.Create));
        document.Open();

        ArrayList objects;
        document.NewPage();

        var stream = new StreamReader(strHTMLpath, Encoding.Default).ReadToEnd();
        objects = iTextSharp.text.html.simpleparser.
        HTMLWorker.ParseToList(new StreamReader(strHTMLpath, Encoding.UTF8), styles);            

        BaseFont bf = BaseFont.CreateFont("c:\\windows\\fonts\\Tahoma.ttf",
                                        BaseFont.IDENTITY_H, true);
        for (int k = 0; k < objects.Count; k++)
        {
            PdfPTable table = new PdfPTable(1);
            table.RunDirection = PdfWriter.RUN_DIRECTION_RTL;

            var els = (IElement)objects[k];
            foreach (Chunk el in els.Chunks)
            {
                #region set persian font
               iTextSharp.text.Font f2 = new iTextSharp.text.Font(bf, el.Font.Size,
                                                el.Font.Style, el.Font.Color);
                el.Font = …
Run Code Online (Sandbox Code Playgroud)

html c# asp.net localization

6
推荐指数
1
解决办法
5610
查看次数

标签 统计

asp.net ×1

c# ×1

html ×1

localization ×1