My application is MVC c#, I use itextSharp 5.3.4 to generate PDF using an existing template. I add text to the form fields (from sql database) using:
pdfFormFields.SetField("Notes", cth.Notes.ToString());
The challenge I have is adding html contents, for example:
text text <img alt="" height="133" src="/Content/UserFiles/635380078478327671/Images/test.png" width="179" />
I used before HTMLWorker to generate paragraphs using:
public Paragraph CreateSimpleHtmlParagraph (String text)
{
string fontpath = System.Web.HttpContext.Current.Server.MapPath("~/Content/");
BaseFont bf = BaseFont.CreateFont(fontpath + "ARIALUNI.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
var f = new Font(bf, 10, Font.NORMAL);
var p = new Paragraph { Alignment = Element.ALIGN_LEFT, Font = f };
var styles = new StyleSheet();
styles.LoadTagStyle(HtmlTags.SPAN, HtmlTags.FONTSIZE, "10");
styles.LoadTagStyle(HtmlTags.BODY, HtmlTags.ENCODING, BaseFont.IDENTITY_H);
using (var sr = new StringReader(text))
{
var elements = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(sr, styles);
foreach (var e in elements)
{
p.Add(e);
}
}
return p;
}
Can't figure out how can I add the paragraph to the form field, or even add a new page to the existing form or generating a new document and merging the form and the new document. Would appreciate your suggestions.