Itextsharp Pdf Data

Active3 years, 1 month ago

Not reading fields from a PDF using iTextSharp Read table array from PDF file, itextsharp to Read PDF file with itextsharp dll then extract data in data table. Here Mudassar Ahmed Khan has explained with an example, how to use the iTextSharp HTML to PDF conversion library in ASP.Net MVC Razor. First the data will be populated from database using Entity Framework and then the records from the database will be displayed as HTML in ASP.Net MVC Razor.

I'd like to know if ITextSharp has the capability of converting HTML to PDF. Everything I will convert will just be plain text but unfortunately there is very little to no documentation on ITextSharp so I can't determine if that will be a viable solution for me.

Itextsharp Pdf Data

If it can't do it, can someone point me to some good, free .net libraries that can take a simple plain text HTML document and convert it to a pdf?

tia.

Simon Martin
3,0127 gold badges48 silver badges84 bronze badges
KyleKyle
4,79917 gold badges47 silver badges61 bronze badges

8 Answers

I came across the same question a few weeks ago and this is the result from what I found. This method does a quick dump of HTML to a PDF. The document will most likely need some format tweaking.

meJustAndrew
3,3644 gold badges27 silver badges53 bronze badges
Jonathan

Itextsharp Pdf Data Download

Jonathan
1,7111 gold badge15 silver badges19 bronze badges

after doing some digging I found a good way to accomplish what I need with ITextSharp.

Here is some sample code if it will help anyone else in the future:

Fredrik Hedblad
72.9k20 gold badges226 silver badges255 bronze badges
KyleKyle
4,79917 gold badges47 silver badges61 bronze badges

Here's what I was able to get working on version 5.4.2 (from the nuget install) to return a pdf response from an asp.net mvc controller. It could be modfied to use a FileStream instead of MemoryStream for the output if that's what is needed.

I post it here because it is a complete example of current iTextSharp usage for the html -> pdf conversion (disregarding images, I haven't looked at that since my usage doesn't require it)

It uses iTextSharp's XmlWorkerHelper, so the incoming hmtl must be valid XHTML, so you may need to do some fixup depending on your input.

µBioµBio

Itextsharp Pdf Documentation

9,3146 gold badges33 silver badges54 bronze badges

I would one-up'd mightymada's answer if I had the reputation - I just implemented an asp.net HTML to PDF solution using Pechkin. results are wonderful.

There is a nuget package for Pechkin, but as the above poster mentions in his blog (http://codeutil.wordpress.com/2013/09/16/convert-html-to-pdf/ - I hope she doesn't mind me reposting it), there's a memory leak that's been fixed in this branch:

The above blog has specific instructions for how to include this package (it's a 32 bit dll and requires .net4). here is my code. The incoming HTML is actually assembled via HTML Agility pack (I'm automating invoice generations):

again, thank you mightymada - your answer is fantastic.

Carl SteffenCarl Steffen

I prefer using another library called Pechkin because it is able to convert non trivial HTML (that also has CSS classes). This is possible because this library uses the WebKit layout engine that is also used by browsers like Chrome and Safari.

I detailed on my blog my experience with Pechkin: http://codeutil.wordpress.com/2013/09/16/convert-html-to-pdf/

mightymadamightymada

The above code will certainly help in converting HTML to PDF but will fail if the the HTML code has IMG tags with relative paths. iTextSharp library does not automatically convert relative paths to absolute ones.

I tried the above code and added code to take care of IMG tags too.

You can find the code here for your reference:http://www.am22tech.com/html-to-pdf/

SoanSoan
Itextsharp read pdf data

It has ability to convert HTML file in to pdf.

Required namespace for conversions are:

and for conversion and download file :

Christian
21.5k12 gold badges93 silver badges144 bronze badges
Nitin SinghNitin Singh

If you are converting html to pdf on the html server side you can use Rotativa :

This is based on wkhtmltopdf but it has better css support than iTextSharp has and is very simple to integrate with MVC (which is mostly used) as you can simply return the view as pdf:

meJustAndrewmeJustAndrew

Itextsharp Examples

3,3644 gold badges27 silver badges53 bronze badges

Itextsharp Pdf Download

Not the answer you're looking for? Browse other questions tagged .netitextsharphtml-to-pdf or ask your own question.