views:

1004

answers:

11

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?

A: 

These links may help:

http://www.411asp.net/home/assembly/document/pdf

http://alt-soft.com/Support_kb_generating_pdf_from_asp_net.aspx

Some languages can do this out of the box, and you can get some external services that can produce a pdf as well, but it looks like an asp.net solution is really what you need.

HTH

Ryan Guill
+5  A: 

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.

jcollum
If it's not a simple grid, iTestSharp is not really appropriate for his needs though - he needs a one-step html to PDF conversion, not to rewrite the whole page line-by-line again as a PDF.
MGOwen
+3  A: 

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.

http://pdfsharp.com/PDFsharp/

Mr. Pig
A: 

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.

Glennular
A: 

As long as you can make sure to use proper XHTML, you could also use a product like Alt-Soft's Xml2PDF to convert XML (XHTML) into PDF by means of XSLT/XSL-FO.

It takes a bit of a learning curve to master, but it works very well once you've "got" it!

Marc

marc_s
A: 

If you are specifically focused on PDF generation, I can recommend the Dynamic PDF products from CeTe. They are a bit expensive but they have a lot of options, are easy to use and are fairly well documented.

Mark Brittingham
+6  A: 

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!

jle
Find it at: http://code.google.com/p/wkhtmltopdf/ It looks pretty good from a few quick tests. It should do the job if GPLv3 works for you.
RBerteig
anywhere I can get windows binaries???
opensas
http://code.google.com/p/wkhtmltopdf/ and it is a single binary for windows
jle
Note it's still in beta and does have issues (chokes sometimes with no real explanation, can't do page breaks on some pages) at time I'm writing this - but it is good (with most other solutions the PDF looks nothing like the original page), simple to use and free.
MGOwen
A: 

I agree with jle, wkhtmltopdf works really good.. quick ad quality-strong

DaNieL
A: 

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

Dan
+1  A: 

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.

jhs
A: 

Use PDF Duo .NET converting component. It converts HTML to PDF so after generation your HTML report you can create alse the PDF in your ASP.NET project.

Constantine