iTextSharp upgrade to iText7 .NET

iTextSharp upgrade to iText7 .NET



This is my iText5 code that does what I have previously required done with HTML snippets;


//GetFieldPositions returns an array of field positions if you are using 5.0 or greater
rectangle = pdfStamper.AcroFields.GetFieldPositions(field.Key)[0].position;

//tell itextSharp to overlay this content
PdfContentByte contentBtye = pdfStamper.GetOverContent(1);

var elements = XMLWorkerHelper.ParseToElementList(pdfPlaceHolderData[key].ToString(), null);

ColumnText ct = new ColumnText(contentBtye);

ct.SetSimpleColumn(rectangle.Left, rectangle.Bottom, rectangle.Right, rectangle.Top);

ct.Add(elements);

ct.Go(false);

pdfFormFields.SetField(field.Key, string.Empty);



I am struggling to see how to convert this to work in iText7 .NET.



XMLWorkerHelper.ParseToElementList returns 'ElementList' which inherits 'List'. 'IElement' is structured as follows;



iTextSharp IElement



The iText7 Html2Pdf call to HtmlConverter.ConvertToElements(html) returns an 'IList'. However 'IElement' is now structured as follows;



iText7 IElement



I was hoping that I could of just used this result but obviously my call to 'ct.Add(elements);' in the above code chokes because of the different IElement structure.



I know I am trying to cut corners here (I have no choice at the moment); is there a relatively easy way to convert the iText7 IElement to the iTextSharp IElement that will retain my nicely parsed HTML with images?



How can I replace an acro form field content with parsed HTML instead? This would preferably be in iTextSharp 5, but I suppose would be even better using the latest version?



I currently have a solution working happily with iTextSharp 5 that allows PDF templates to populated dynamically. I have hit a problem using the XMLWorkerHelper.ParseToElementList as it does not seem to support parsing inline images.


XMLWorkerHelper.ParseToElementList



I have found that iText7 for .net has an extension called html2pdf that has a method called HtmlConverter.ConvertToElements that does perfectly parse HTML with inline images however the result is not compatible with my iTextSharp 5 implementation and I am struggling in trying to convert it.


html2pdf


HtmlConverter.ConvertToElements





How's it failing in iTextSharp 7?
– orhtej2
Sep 2 at 18:07






You probably should move the last paragraph of your question up to the front as that appears to be your actual problem.
– mkl
Sep 3 at 4:45





orhtej2 - thank you for your response, I have added more detail of the issue I have to the post. mkl I have edited my post as per your suggestion.
– Reggie
Sep 3 at 9:48






I just came back to your question to think of some solution but I now see that it is not clear what you really want. On one hand your want to know "how to convert this to work in iText7 .NET" but on the other hand you say it "would preferably be in iTextSharp 5". So where are you heading? Obviously, though, it hardly makes any sense to try and use the pdfHTML of iText 7 for iText 5 document manipulation.
– mkl
Sep 9 at 10:16





mkl - you are correct, it is not exactly clear. My problem is I have inherited a full project that is built on iTextSharp5 and this is where my problem is. Everything works as required EXCEPT when there is HTML that has inline images as XMLWorkerHelper.ParseToElementList does not parse these images at all. I stumbled on iText7's html2pdf does parse the HTML perfectly. I am not in a position where I can confidently argue for a rewrite to use iText 7 so was desperately hoping to be able to get this HTML to parse correctly using iTextSharp, and that is where I am stuck!
– Reggie
Sep 12 at 11:33






Thanks for contributing an answer to Stack Overflow!



But avoid



To learn more, see our tips on writing great answers.



Some of your past answers have not been well-received, and you're in danger of being blocked from answering.



Please pay close attention to the following guidance:



But avoid



To learn more, see our tips on writing great answers.



Required, but never shown



Required, but never shown




By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

Edmonton

Crossroads (UK TV series)