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.
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.
This license is a commercial license. You have to pay for it. To answer your question: iText can be used for free in situations where you also distribute your software for free. As soon as you want to use iText in a closed source, proprietary environment, you have to pay for your use of iText.
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.
private MemoryStream createPDF(string html) { MemoryStream msOutput = new MemoryStream(); TextReader reader = new StringReader(html); // step 1: creation of a document-object Document document = new Document(PageSize.A4, 30, 30, 30, 30); // step 2: // we create a writer that listens to the document // and directs a XML-stream to a file PdfWriter writer = PdfWriter.GetInstance(document, msOutput); // step 3: we create a worker parse the document HTMLWorker worker = new HTMLWorker(document); // step 4: we open document and start the worker on the document document.Open(); worker.StartDocument(); // step 5: parse the html into the document worker.Parse(reader); // step 6: close the document and the worker worker.EndDocument(); worker.Close(); document.Close(); return msOutput; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With