Kia*_*sos 6 html c# asp.net localization
我使用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 = f2;
#endregion set persian font
#region Set right to left for persian words
PdfPCell cell = new PdfPCell(new Phrase(10, el.Content, el.Font));
cell.BorderWidth = 0;
table.AddCell(cell);
#endregion Set right to left for persian words
}
//document.Add((IElement)objects[k]);
document.Add(table);
}
document.Close();
Response.Write(strPDFpath);
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader("Content-Disposition", "attachment; filename=" + strPDFpath);
Response.ContentType = "application/octet-stream";
Response.WriteFile(strPDFpath);
Response.Flush();
Response.Close();
if (File.Exists(strPDFpath))
{
File.Delete(strPDFpath);
}
Run Code Online (Sandbox Code Playgroud)
我的左翼和转换波斯语的权利得到了解决,但还有另一个问题.
我的算法无法解析和转换在html文件中使用的表标记的内容.
现在的问题是:如何解析具有表格标签,div和段落标签与波斯语句子的html文件,并将其转换为pdf?
| 归档时间: |
|
| 查看次数: |
5610 次 |
| 最近记录: |