0

I have a project where I need to create an HTML form (no problem) and then create a PDF file from the results using C#.

I have done this before in PHP using FPDF but this one needs to be C#. Ideally I want to put the code into a user control and then stick it in an Umbraco website.

Can anyone recommend a good way to do this? PDF doesn't need to be fancy, it'll just display text, we aim to create a generic purchase order based on what the customer wants from the form, which can then be emailed to them to print off on headed paper.

Thanks

John Halsey
  • 1,930
  • 3
  • 19
  • 41

3 Answers3

1

There are a couple of recent problems with iTextSharp. The most annoying is that in the latest version they've deprecated the HTML parser. So now everything has to work through the XMLWorkerHelper singleton and parses through ParseXHtml. I find this a real pain, since HTML pages which aren't well formed appear fine on browser, parse OK in the old method and now crash out with an exception. So it necessitates an extra step to make sure your HTML is well formed (as XHTML) first. If you are generating your HTML from an ASPX page, then using Server.Execute() to get the stream, then this might be useful to you for iTextSharp:

http://jwcooney.com/2012/12/30/generate-a-pdf-from-an-asp-net-web-page-using-the-itextsharp-xmlworker-namespace/

Be mindful that iTextSharp has a distinct lack of any decent documentation of the modern changes (being mindful that the Java iText documents don't translate perfectly to C#), it makes the learning curve far too long and steep for any practical use in short spaces of time. I've basically given up on that platform, though may just create a baseline system to get something working lean whilst I then learn another framework.

As a result, I'm looking at PDFizer and PDFSharp libraries. If I have some success, I'll report back.

0

here is a library for converting HTML to PDF

http://pdfcrowd.com/web-html-to-pdf-net/

Loki
  • 286
  • 2
  • 7
0

I like the PDFsharp library. Not sure how it would work for your needs, though.

TaW
  • 53,122
  • 8
  • 69
  • 111