HTML document to PDF?

后端 未结 6 870
臣服心动
臣服心动 2020-12-29 00:55

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?

相关标签:
6条回答
  • 2020-12-29 01:16

    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/

    0 讨论(0)
  • 2020-12-29 01:17

    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!

    0 讨论(0)
  • 2020-12-29 01:18

    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.

    0 讨论(0)
  • 2020-12-29 01:27

    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.

    0 讨论(0)
  • 2020-12-29 01:31

    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

    0 讨论(0)
  • 2020-12-29 01:41

    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.

    0 讨论(0)
提交回复
热议问题