我有一个带有一些文本和图像的HTML代码,该代码将转换为PDF。但是在生成PDF时,可以完美地生成文本,但是图像将被忽略。我正在使用Itext 5.5.13和itextsharp.xmlworker 5.5.13。 以下是生成pdf的C#代码:
using (var ms = new MemoryStream())
{
//Create an iTextSharp Document which is an abstraction of a PDF but **NOT** a PDF
using (var doc = new Document(PageSize.A4, 40, 40, 215, 180))
{
//Create a writer that's bound to our PDF abstraction and our stream
using (var writer = PdfWriter.GetInstance(doc, ms))
{
writer.PageEvent = new ITextEvents();
//Open the document for writing
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://localhost:4119/upload/ReportImages/files/photo-x-ray-head-and-brain.jpg" style="width: 1023px; height: 682px;" /></span> </span></span></b></span></span></span></p>
</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;
}
转换为Pdf时,其外观如下 [底部图像未显示]:
任何建议都会有所帮助。