Itextsharp Base64 Embedded Image In Header Not Parsing/showing
Background: I have an editor where I can edit the header and footer of a document in HTML and then merge them into the main document. Base64 Embedded images work perfectly within t
Solution 1:
So i figured out the answer to this. Pipeline processing for the main document did not apply to the writers that built the headers and footers.
I had to setup the tagprocessors, cssresolvers, fonts and pipelines within the pageevent as well. Once this was done, the images were processed and bytes of the processed images were applied to the main document on every pageevent (or pageend)
so my code became
IfMe.UsesHeader Then
headerElements = New ElementList() 'XMLWorkerHelper.ParseToElementList(Me.HeaderHTML, Nothing)
headerTable = SetTable(headerElements, Me.HeaderHTML)
CalculatedHeaderHeight = headerTable.Rows(0).MaxHeights
EndIfIfMe.UsesFooter Then
footerElements = New ElementList() 'XMLWorkerHelper.ParseToElementList(Me.HeaderHTML, Nothing)
footerTable = SetTable(footerElements, Me.FooterHTML)
CalculatedFooterHeight = footerTable.Rows(0).MaxHeights
EndIf
where footerElements
and headerElements
are of type ElementList
and the SetTable function is :
PublicFunctionSetTable(ByVal elements As ElementList, ByVal htmlcode AsString) AsPdfPTableDimtagProcessorsAsDefaultTagProcessorFactory = CType(Tags.GetHtmlTagProcessorFactory(), DefaultTagProcessorFactory)
tagProcessors.RemoveProcessor(HTML.Tag.IMG) ' removethedefaultprocessortagProcessors.AddProcessor(HTML.Tag.IMG, New CustomImageTagProcessor()) ' useournewprocessorDimcssResolverAsICSSResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(True)
cssResolver.AddCssFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets/css/pdf.css"), True)
'SetupFontsDimxmlFontProviderAsXMLWorkerFontProvider = NewXMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS)
xmlFontProvider.RegisterDirectory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "assets/fonts/"))
DimcssAppliersAsCssAppliers = NewCssAppliersImpl(xmlFontProvider)
DimhtmlContextAsHtmlPipelineContext = NewHtmlPipelineContext(cssAppliers)
htmlContext.SetAcceptUnknown(True)
htmlContext.SetTagFactory(tagProcessors)
DimpdfAsElementHandlerPipeline = NewElementHandlerPipeline(elements, Nothing)
DimhtmlpAsHtmlPipeline = NewHtmlPipeline(htmlContext, pdf)
DimcssAsCssResolverPipeline = NewCssResolverPipeline(cssResolver, htmlp)
DimworkerAsXMLWorker = NewXMLWorker(css, True)
DimpAsXMLParser = NewXMLParser(worker)
'DimholderTableAsNewPdfPTable({1})
DimholderTableAsPdfPTable = NewPdfPTable({1})
holderTable.HorizontalAlignment = Element.ALIGN_LEFTDimholderCellAsNewPdfPCell()
holderCell.Padding = 0
holderCell.UseBorderPadding = FalseholderCell.Border = 0
p.Parse(New MemoryStream(System.Text.Encoding.ASCII.GetBytes(htmlcode)))
ForEachelAsIElementInelementsholderCell.AddElement(el)
NextDimholderRowAsNewPdfPRow({holderCell})
holderTable.Rows.Add(holderRow)
holderTable.WidthPercentage = 100
ReturnholderTableEndFunction
And this solved my problem
Post a Comment for "Itextsharp Base64 Embedded Image In Header Not Parsing/showing"