iTextSharp How include GenericTag using XML Parsing
I'm using iTextSharp library, specifically to view .xml documents and transform them into .p开发者_StackOverflowdf files as follows:
var docWriter = PdfWriter.GetInstance(document, new FileStream("DOC.pdf", FileMode.Create));
ITextHandler xmlHandler = new ITextHandler(document);
xmlHandler.Parse("MLDOC.xml");
I need to know if there is any way to include any attribute within the tags in my .xml file to indicate that they are GenericTag, or otherwise how I can identify a paragraph which I include a PdfAnnotation for example. I've tried to subscribe to the event OnGenericTag, but using the XML parser: xmlHandler.Parse("MLDOC.xml");, this method is never executed
Thanks!
You're using an Old version of iText. I strongly recommend you get a more recent version... A post-5.0 release if you're okay with the AGPL, something prior (4.2 IIRC) if you'd rather stick with LGPL/MPL.
There ISN'T an iTextHandler class anymore.
You need to add the generic tags to the iText elements as they're created before iText will call your OnGenericTag handler.
The only way I can think to do this would be to Change The Source. For HTMLWorker, you'd have to change FactoryProperties so it'd look for some magic attributes you'd introduce for the generic tag's value.
In the 5.0.6 iTextSharp source, it looks like you'd want to modify ElementFactory.CreateChunk(), and insert something like:
if (chain.HasProperty(MY_MAGIC_PROPERTY)) {
ck.setGenericTag( chain[MY_MAGIC_PROPERTY] );
}
Issue: ChainedProperties propagate to their child nodes. If you tagged a table with a generic tag, EVER CHUNK IN THAT TABLE would have that tag. Probably not what you want. }
精彩评论