我有一个html页面,我需要将其转换为pdf html页面由gridview和图像组成,在网上搜索我知道这可以使用ItextSharp完成但是当我尝试使用以下代码时pdf正在生成,但没有任何对齐,我无法得到gridview你可以建议任何更好的方法或下面的代码是什么错误?
protected void btnExportPDF_Click()
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition",
"attachment;filename=GridViewExport.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.PDFForm.RenderControl(hw);
StringReader sr = new StringReader(sw.ToString());
iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 10f, 10f, 10f, 0f);
iTextSharp.text.html.simpleparser.HTMLWorker htmlparser = new iTextSharp.text.html.simpleparser.HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();
}
答案 0 :(得分:1)
1)您可以尝试 Winnovative HTML to PDF Conversion 工具(付费版)。它的架构是STA。
http://www.winnovative-software.com/HTML-to-PDF-Conversion-Fine-Control.aspx
2)优越的速度和速度批量生成包含数百页的PDF文档,我建议使用基于服务器的软件,例如 PDFReactor 。它的许可证价格很高。它的架构是MTA。
我在商业上尝试了这两种方法,并在其中一个需要将自定义用户Html呈现为PDF文件的项目中选择了PDFReactor。
答案 1 :(得分:0)
您可以尝试使用GemBox.Document,我认为它可能符合您的需求。