iTextSharp Html阿拉伯语混合内容为PDF

时间:2016-01-18 08:52:25

标签: pdf itext

我们正处于教育领域的项目中,我们正在寻找导入阿拉伯语内容,图像(uri / base64加密文本),html表格。

我们在使用HtmlWorker和Stream数据执行时遇到问题。它会因为“文档没有页面”而引发错误

string str="html content contains arabic font texts/images";
using (MemoryStream ms = new MemoryStream())
{
    using (iTextSharp.text.Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 25, 25, 30, 30))
    {
        using (iTextSharp.text.pdf.PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document,ms))
        {
           using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(document))
           {
             //HTMLWorker doesn't read a string directly but instead needs a TextReader (which StringReader subclasses)
             using (var sr = new StreamReader(str))  /// We are facing issue at this juncture where it throws error.
             {
               //Parse the HTML
               htmlWorker.Parse(sr);
             }
           }

           document.Close();
           writer.Close();
           ms.Close();

           Response.ContentType = "pdf/application";
           Response.AddHeader("content-disposition", "attachment;filename=First_PDF_document.pdf");
           Response.OutputStream.Write(ms.ToArray(), 0, ms.ToArray().Length);
        }
    }
}

你可以帮我们解决这个问题吗?

现在,

我尝试过其他方法:

 using (var htmlWorker = new iTextSharp.text.html.simpleparser.HTMLWorker(document))
                        {
                            using (Stream s = GenerateStreamFromString(str))
                            {
                                using (var srt = new StreamReader(s))
                                {
                                    //Parse the HTML
                                    htmlWorker.Parse(srt); //this line throws error now.
                                }
                            }
                        }


  public Stream GenerateStreamFromString(string s)
    {
        MemoryStream stream = new MemoryStream();
        StreamWriter writer = new StreamWriter(stream);
        writer.Write(s);
        writer.Flush();
        stream.Position = 0;
        return stream;
    }

错误讯息:

  

“指定的路径,文件名或两者都太长。完全限定的文件名必须少于260个字符,目录名称必须少于248个字符。”

0 个答案:

没有答案