I have a HTML code with some text and an image, which is to be converted to PDF. But when generating PDF, text is generated perfectly but the image is being ignored. I am using Itext 5.5.13 and itextsharp.xmlworker 5.5.13.When converted to pdf, the expected result was that, the text with image should have come at the bottom, but no image is shown.
Below is the c# code to generate pdf :
using (var ms = new MemoryStream())
{
using (var doc = new Document(PageSize.A4, 40, 40, 215, 180))
{
using (var writer = PdfWriter.GetInstance(doc, ms))
{
writer.PageEvent = new ITextEvents();
doc.Open();
string Report_Html_Text = " <div>
<p align="center" style="margin-bottom:.0001pt; text- align:center; margin:0in 0in 10pt">
<span style="font-size:11pt">
<span style="font-family:"Arial","sans- serif"">CT Scan Of Brain</span>
</u></b></span>
</p>
<p style="margin-bottom:.0001pt; margin:0in 0in 10pt;font-size:11pt;line-height:115%;font-family:Calibri,sans-serif">
<b><u><span style="font-size:12.0pt">
<span style="font-family:"Arial","sans-serif& quot;">Procedure </span></span>
</u></b>
</span>
</p>
<p style="margin-bottom:.0001pt; margin:0in 0in 10pt;font-size:11pt;line-height:115%;font- family:Calibri,sans-serif;">
<span style="font-family:"Arial","sans-serif"">CT Scan of brain –
<b>Plain and contrast</b> study.</span></span>
</p>
<ul>
<li style="margin-top:0in; margin-right:0in; margin- bottom:.0001pt; margin:0in 0in 10pt;font-size:11pt;line-height:115%;font-family:Calibri,sans-serif;">
<span style="font-family:"Arial","sans- serif"">No detectable abnormalities are present in
<b>posterior fossa</b> structures including <b>fourth ventricle.</b></span>
</li>
<li style="margin-top:0in; margin-right:0in; margin- bottom:.0001pt; margin:0in 0in 10pt;font- size:11pt;line-height:115%;line-height:115%;">
<span style="font-family:"Arial","sans-serif"">Sylvian fissures cortical sulci and basal subarachnoid spaces are widened.</span>
</li>
</ul>
<ul>
<li style="margin-top:0in; margin-right:0in; margin-bottom:.0001pt; margin:0in 0in 10pt"><span style="font-size:11pt"><span style="line-height:115%"><span style="font-family:Calibri,sans-serif"><b>
<span style="line-height:115%"><span style="font-family:"Arial","sans-serif"">Supratentorial ventricles</span></span></b>
<span style="line-height:115%"><span style="font-family:"Arial","sans-serif""> are dilated with septum in midline.</span></span></span> </span></span>
</li>
<li style="margin-top:0in; margin-right:0in; margin-bottom:.0001pt; margin:0in 0in 10pt"><span style="font-size:11pt"><span style="line-height:115%"><span style="font-family:Calibri,sans-serif"><b><span style="line-height:115%"><span style="font-family:"Arial","sans-serif"">No focal</span></span></b><span style="line-height:115%">
<span style="font-family:"Arial","sans-serif""> abnormal area is present in the supratentorial brain parenchyma.</span></span></span> </span></span>
</li>
<img alt="" src="http:
</div> ";
using (var srHtml = new StringReader(Report_Html_Text))
{
iTextSharp.tool.xml.XMLWorkerHelper.GetInstance().ParseXHtml(writer, doc, srHtml);
}
doc.Close();
}
}
Byte[] bytes = ms.ToArray();
return bytes;
}
What I have tried:
Previously I uses Htmlworker, but as it is depreciated, I used XMLWorker instead to genrate pdf. Xmlworker is respecting the html tags and indentation, but ignored the image, and I have used the absolute Url .