Generate PDF from ASP.NET from Raw HTML/CSS Content

Generate PDF from ASP.NET from raw HTML/CSS content?

There is no way to generate a PDF from an HTML string directly within .NET, but there are number of third party controls that work well.

I've had success with this one: http://www.html-to-pdf.net
and this: http://www.htmltopdfasp.net

The important questions to ask are:

  1. Does it render correctly as compared to the 3 major browsers: IE, FF and Safari/Chrome?
  2. Does it handle CSS fine?
  3. Does the control have it's own rendering engine? If so, bounce it. You don't want to trust a home grown rendering engine - the browsers have a hard enough problem getting everything pixel perfect.
  4. What dependencies does the third party control require? The fewer, the better.

There are a few others but they deal with ActiveX displays and such.

Generating Pdf from webpage in asp.net

ITextSharp does almost what you ask and is Open Source, however the API for conversion process has not been touched for years and is outdated. I therefore would recommend a commercial product.

Something like Winnovative HTML to PDF Converter

To be honest I look at it like this, you can save money by buying a licence for a commercial product rather than spending days developing a solution yourself.

Edit If it is for generating invoices alone then I would use iTextSharp as it does not take long to learn the basics. However if you want to be able to convert a full rich webpage into a PDF then go down the commercial route.

Generate PDF with PDFSharp from HTML template and send to browser

I figured out the problem. Apparently it was because I was doing an ajax request via the update panels. It works fine without the ajax.

How to convert HTML to PDF

Try this one http://code.google.com/p/wkhtmltopdf/

How can I return a pdf from a web request in ASP.NET?

Assuming you can get a byte[] representing your PDF:

Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("Content-Disposition",
"attachment;filename=\"FileName.pdf\"");

Response.BinaryWrite(yourPdfAsByteArray);

Response.Flush();

Response.End();

Convert html tagged text to string for a pdf itext7

I created "Hello World" here and used bold, italic and underline. Copy the source code via "Tools" and just use the following code to convert it via iText7:

String htmlString = "<p><span style=\"text-decoration: underline;\"><em><strong>Hello World</strong></em></span></p>";
HtmlConverter.convertToPdf(htmlString, new PdfWriter(destinationFolder + "test.pdf"));

The resultanting PDF:

Sample Image



Related Topics



Leave a reply



Submit