如何使用itextsharp并使用Literal将阿拉伯字符打印到pdf文件? [英] How to print arabic characters to a pdf file using itextsharp and using Literal?
本文介绍了如何使用itextsharp并使用Literal将阿拉伯字符打印到pdf文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
LitCompleteDetails.Text = CompleteDetails();
Response.Clear(); //this clears the Response of any headers or previous output
Response.Buffer = true; //ma
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Transport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
LitCompleteDetails.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
Document pdfDoc = new Document();
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
推荐答案
第1步:
在此步骤中,您需要下载阿拉伯语的.ttf文件。这是链接:
下载传统阿拉伯字体 - 酷文本 [ ^ ]
第2步:
在此步骤中,您需要加载.ttf(您下载的是哪一个)并将文本写入Pdfobject。
Step1:
In this Step, you need to download .ttf file for Arabic language. Here is the link:
Download Traditional Arabic Font - Cool Text[^]
Step2:
In this step you need to load the .ttf(which one you downloaded) and write the text to Pdfobject.
BaseFont bf = BaseFont.CreateFont(Environment.GetEnvironmentVariable("windir") + @"\fonts\ArialUni.TTF", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
PdfPTable table = new PdfPTable(GridView1.Columns.Count);
//Set Font and Font Color
Font font = new Font(bf, 10, Font.NORMAL);
font.Color = new Color(GridView1.HeaderStyle.ForeColor);
PdfPCell cell = new PdfPCell(new Phrase(12, "Arabic Text", font));
//Set Header Row BackGround Color
cell.BackgroundColor = new Color(GridView1.HeaderStyle.BackColor);
table.AddCell(cell);
点击以下链接,可能对您有所帮助:
使用不同语言的iTextSharp将GridView导出为PDF字符 [ ^ ]
这篇关于如何使用itextsharp并使用Literal将阿拉伯字符打印到pdf文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文