Update
The images problem was solved in thread http://www.vbforums.com/showthread.php?t=651424
The code below opens a template copies is and creates a new document from it and adds the html to the document.
My outstanding issue is that the template actually just holds an image like a header, when I add the additional html generated text it is added at the same place as the header rather than after.
I need to figure out where the template content ends and only add the additional content after.
Code:public void GeneratePDFDoc(string htmlText) { int pageNumber = 1; PdfReader reader = new PdfReader(Server.MapPath(ConfigurationManager.AppSettings["PDFPath"].Trim()) + "/" +"Template.pdf"); iTextSharp.text.Rectangle size = reader.GetPageSizeWithRotation(pageNumber); Document doc = new Document(size); PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(Server.MapPath(ConfigurationManager.AppSettings["PDFPath"].Trim()) + "/" + Code + ".pdf", FileMode.Create, FileAccess.Write)); doc.Open(); PdfContentByte cb = writer.DirectContent; doc.NewPage(); PdfImportedPage page = writer.GetImportedPage(reader, pageNumber); cb.AddTemplate(page, 0, 0); String htmlText = ReturnHTMLString(htmlText); htmlText = RemoveHyperLinks(htmlText); htmlText = LocalizeImages(htmlText); List<IElement> htmlarraylist = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(htmlText),null); for (int k = 0; k < htmlarraylist.Count; k++) { doc.Add((IElement)htmlarraylist[k]); } doc.Close(); }





Reply With Quote