Directly convert .aspx to .pdf [closed]

末鹿安然 提交于 2019-12-17 06:07:24

问题


A project I am working on requires me to build a report that is output in both HTML (.aspx) and as a PDF. Is there a solution available that allows me to feed the output of an .aspx page to a PDF generation utility? Full support of HTML and CSS would be ideal.

Thanks!


回答1:


wkhtmltopdf will do it.... USAGE:

wkhtmltopdf http://www.google.com google.pdf

That is it. You can go to any web page... even aspx. css is supported better than any other utility as it uses the webkit html rendering engine (Safari, Chrome). Enjoy

There is a single .exe (7 mb) that can be used from .Net simply by using Process.Start Make sure that you copy the exe into your project directory or you have to specify the full path. ex:

static void HtmlToPdf(string website,string destinationFile)
    {
        ProcessStartInfo startInfo = new ProcessStartInfo();
        startInfo.FileName = "wkhtmltopdf.exe";
        startInfo.Arguments = website+" "+destinationFile;
        Process.Start(startInfo);
    }  

I think SSL is supported but I do not think that 2-way SSL would work at the moment. It is hands down the best single stop HTML -> PDF tool I have seen.




回答2:


iTextSharp can do HTML to PDF, but only basic HTML and CSS not full support.

Some articles on sending HTML to iTextSharp:

http://somewebguy.wordpress.com/2009/05/08/itextsharp-simplify-your-html-to-pdf-creation/

http://aspdotnetcodebook.blogspot.com/2008/07/how-to-export-content-of-gridview-to.html

http://geekswithblogs.net/casualjim/archive/2005/11/13/59943.aspx#393262




回答3:


I used HTMLDoc in the past it did a good job of turning HTML tables, images etc with some basic formatting into a decent PDF report. There also seems to be an open source version as well.

iTextSharp renders html at a basic level.

I found that hacking in a simple HTML renderer allowed me to offer PDF functionality immediately and then i had to backfit a PDF report renderer later. This should be pretty simple if you keep your presentation layer separate from your data and business logic.

I used PDFlib then but both iTextSharp and PDFlib are awesome libraries for programatically creating PDF from your data sources.

I haven't seen a perfect HTML 2 PDF renderer yet, so i would plan for a two stage approach. You may also want to look at this question for other options.




回答4:


AspPDF is an ActiveX server component for dynamically creating, reading and modifying Portable Document Format (PDF) files.

http://www.asppdf.com




回答5:


ActivePDF WebGrabber is a great product once you have everything configured correctly. It's costly, but it has awesome support of HTML and CSS.




回答6:


We've used the Alt-Soft XML2PDF product for this purpose. It can convert any XML file to PDF using the XSL-FO markup language.

So if your ASPX pages are XHTML compatible, Xml2PDF will convert those into PDF quite happily and easily. Here's a sample page - complete with a downloadable ASP.NET sample - that show how that works: http://www.alt-soft.com/products_HTML2PDF.aspx

It's not free, but well worth its license price!

Marc




回答7:


http://aspdotnetcodebook.blogspot.com/2009/04/how-to-convert-web-page-to-pdf.html Shows you how to override Render and change the content to PDF using iTextSharp




回答8:


This is the best control to convert ASPX page to PDF:

http://www.essentialobjects.com/Products/EOPdf/ASPXToPDF.aspx

It's an ASP.NET server control that you can just drop into your page. It automatically handles ASP.NET authentication and sessions. So you can convert your current page even if the page request login and uses session data.



来源:https://stackoverflow.com/questions/1220423/directly-convert-aspx-to-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!