Error in this line
var k = XMLWorkerHelper.GetInstance(); k.ParseXHtml(pdfWriter, document, sr);
// here it gave me an exception: the reference to the object is not installed in the instance of the object
because of the value of any of the input arguments, it was pointed to NULL. We can check it (the variable passing), whether it is null or the value before passing.
This following code is enough to get HTML content and write it to a PDF file
Document pdfDoc = new Document(PageSize.A4, 10, 10, 10, 10); PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(@"D:\Syed\New PDF\PDF.pdf", FileMode.Create));// Output PDF File Path Response.Write("File Created Successfully"); pdfDoc.Open(); XMLWorkerHelper.GetInstance().ParseXHtml(writer, pdfDoc, new StreamReader(@"D:\Syed\test.html"));//This is input HTML file path pdfDoc.Close();
It will be read from an HTML file and written to a PDF file.
source share