我正在尝试使用ASP.NET (C#)将检索到的数据从SQL导出到PDF中。备注:
如何使用ASP.NET将HTML表转换为PDF?
有谁可以帮我?谢谢。
发布于 2013-11-09 23:21:14
您可以尝试使用itextsharp (链接)
示例:
using iTextSharp.text;
using iTextSharp.text.pdf;
using System.IO;
using iTextSharp.text.html;
// step 1 -- get html content
string htmlContent = ... // you html code (for example table from your page)
Document document = new Document();
// step 2:
// we create a writer that listens to the document
// and directs a PDF-stream to a file
PdfWriter.GetInstance(document, new FileStream("c:\\Chap0101.pdf", FileMode.Create));
// step 3: we open the document
document.Open();
// step 4: we add a paragraph to the document
//document.Add(new Paragraph(htmlContent.ToString()));
System.Xml.XmlTextReader _xmlr = new System.Xml.XmlTextReader(new StringReader(htmlContent));
HtmlParser.Parse(document, _xmlr);
// step 5: we close the document
document.Close();发布于 2014-11-19 09:10:50
您可以使用ExpertPdf (www.html-to-pdf.net)。这是一个html到pdf转换器,我一直在使用,最近非常成功。
发布于 2013-11-11 13:24:43
在接受HTML样式内容的解决方案和接受真实HTML的解决方案之间有一个区别。
接受HTML样式或HTML子集的解决方案相当小,并且是独立包含的。但是,您必须完全控制将要使用的HTML,这样才能确保内容符合解决方案的功能。iText XmlTextReader就是一个例子。
其他解决方案基于真实世界的HTML和现实世界的浏览器技术,以获得适当的HTML/CSS/SVG/ etc支持。我们的ABCpdf .NET产品就是一个例子--它包括一个壁虎(FireFox)风格的布局引擎和一个类似IE的三叉戟引擎。
这在很大程度上取决于您对源内容的控制程度。
https://stackoverflow.com/questions/19877873
复制相似问题