I use itextsharp for creating a pdf. I need to place XHTML on it so I uase the XMLWorkerHelper class:
iTextSharp.tool.xml.XMLWorkerHelper worker = iTextSharp.tool.xml.XMLWorkerHelper.GetInstance();
worker.ParseXHtml(pdfWrite, doc, new StringReader(sb.ToString()));
However I would like to specify a position for the parsed XHTML. How do I do that?
EDIT:
I thought I will post the code in the case someone else runs into this. The link provided below was for JAVA and in C# things work a bit different.
First you need a class for gathering the Elements:
class ElementHandlerClass : iTextSharp.tool.xml.IElementHandler
{
public List<IElement> elements = new List<IElement>();
public void Add(iTextSharp.tool.xml.IWritable input)
{
if (input is iTextSharp.tool.xml.pipeline.WritableElement)
{
elements.AddRange(((iTextSharp.tool.xml.pipeline.WritableElement)input).Elements());
}
}
}
Then you use it
ElementHandlerClass ehc = new ElementHandlerClass();
worker.ParseXHtml(ehc, new StringReader(sb.ToString()));
Now you have the elements. Next step is to create a ColumnText and fill it with the Elements:
iTextSharp.text.pdf.ColumnText ct = new iTextSharp.text.pdf.ColumnText(pdfWrite.DirectContent);
ct.SetSimpleColumn(200, 300, 300, 500);
foreach (IElement element in ehc.elements)
ct.AddElement(element);
ct.Go();