Last active
January 11, 2023 08:03
-
-
Save willnss/6195815 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//reference http://stackoverflow.com/questions/15644655/fill-pdf-template-acrofield-with-html-formatted-text-using-itextsharp | |
void AddHTMLToContent(String htmlText,PdfContentByte contentBtye,IList<AcroFields.FieldPosition> pos) | |
{ | |
Paragraph par = new Paragraph(); | |
ColumnText c1 = new ColumnText(contentBtye); | |
try | |
{ | |
List<IElement> elements = HTMLWorker.ParseToList(new StringReader(htmlText),null); | |
foreach (IElement element in elements) | |
{ | |
foreach (Chunk chunk in element.Chunks) | |
{ | |
chunk.Font.Size = 14; | |
} | |
} | |
par.Add(elements[0]); | |
c1.AddElement(par); | |
c1.SetSimpleColumn(pos[0].position.Left, pos[0].position.Bottom, pos[0].position.Right, pos[0].position.Top); | |
c1.Go();//very important!!! | |
} | |
catch (Exception ex) | |
{ | |
throw; | |
} | |
} | |
string htmlText ="<b>Hello</b><br /><i>World</i>"; | |
IList<AcroFields.FieldPosition> pos = form.GetFieldPositions("Field1"); | |
//Field1 is the name of the field in the PDF Template you are trying to fill/overlay | |
AddHTMLToContent(htmlText, stamp.GetOverContent(pos[0].page), pos); | |
//stamp is the PdfStamper in this example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
css not working