How do I convert a HTML page to a .PDF?
I have the iTextSharp.dll on my pc, don't know if that will have the functionality I need though.
Printable View
How do I convert a HTML page to a .PDF?
I have the iTextSharp.dll on my pc, don't know if that will have the functionality I need though.
I don't know if this is helpful but try,
http://www.cutepdf.com/products/cutepdf/writer.asp
Hello,
If you are talking about programmatically creating a PDF, then yes, iTextSharp is definitely what you are after. If you search these forums then you will find a number of examples of doing just what you are after.
Gary
This will do it, just add the reference to iTextSharp and modify the folder path as requiredCode:public void GeneratePDFDoc(string htmlText)
{
Document doc = new Document(PageSize.A4, 50, 50, 50, 50);
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Server.MapPath("FOLDERPATH").Trim()) +"/" +"FileName.pdf", FileMode.OpenOrCreate));
doc.AddDocListener(writer);
doc.Open();
// step 4: we Add some content
//make an arraylist ....with STRINGREADER since its no IO reading file...
List<IElement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText),null);
//add the collection to the document
for (int k = 0; k < htmlarraylist.Count; k++)
{
doc.Add((IElement)htmlarraylist[k]);
}
doc.Close();
}
Nice sample!
The only slight change that I would make, personally, is if Document and PdfWriter implement IDisposable would be to wrap them both in a using/Using block.
Gary