Reputation: 33087
I've got an ASP.NET web page that is a dynamically generated report. For business reasons, this exact report needs to be produced as a PDF. What's the best way to do this? Setting the selected printer to Adobe PDF is not an option.
Learn to programmatically create PDFs from scratch? Is there a way to render it in some browser control, then save the ouput?
Upvotes: 6
Views: 1698
Reputation: 9489
wkhtmltopdf - I compiled it in Windows and it works great. It uses WebKit (Safari, Chrome, etc.) to render an HTML page into PDF, and it is free!
Upvotes: 9
Reputation: 73752
Last year, I did a project with PDFs, and I just learned the PDF format, for which I am very glad.
The PDF specification is available freely, and PDF is quite accessible and easy to understand as a programmer. A PDF is a plain-text document, optionally compressed. Each page is a Cartesian plane, on which you draw geometric shapes one-by-one. It is low level and tailor-made for software-generation. Obviously there are advanced things like glyphs and things, but like any well-architected technology, you can stick to the abstraction layers if you want.
Whether to do direct PDF depends on the complexity of your documents. For basic stuff with like simple graphics, text, and images (for example, an invoice is a good candidate), then I would just write PDF directly. You'll get good experience and you will be in full control.
For more complicated things like tables and pie graphs (for which PDF is too low-level to write directly), then I would look into a library or toolkit of some kind.
Upvotes: 3
Reputation: 1013
Have you looked at SQL Server Reporting Services? If you are using MSSQL 2005/2008 then you probably already have reporting services and you just need to configure it. You can host your reports there and in just a few lines of code get the report as a PDF file.
//create the web request for the report based on a URL that will define export
//format, parameter values, etc.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(reportUrl);
//send creditials if necessary
request.Credentials = new NetworkCredential(userName, password);
//response will contain the PDF file as a stream
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Here is a link that might help as well
Upvotes: 0
Reputation: 46613
If the report is a grid (probably is), this blog post using iTextSharp may help. iTextSharp is good and the most complete PDF API for C# that I've seen.
Upvotes: 4
Reputation: 18225
You didn't mention you if you are looking for an open source solution or a $$ one?
But here's an open source converter: http://sourceforge.net/projects/itextsharp/ which is fairly decent.
Upvotes: -1
Reputation: 3654
I don't know if ABCpdf .NET is free but I've heard good things about it. I think it can render HTML files to PDF's directly.
http://www.websupergoo.com/abcpdf-5.htm
I've used PDFsharp (assuming you're using C# in conjunction with ASP) and it works well. It doesn't render HTML as far as I know though.
Upvotes: 3