0

如果图像 src 属性引用图像文件夹,则它会在 pdf 文件中呈现。如果 src 属性引用内部 url,则不会呈现图像。另一个图像存储在数据库中,这就是我需要指定 url 的原因。

是否需要在图片的 src 属性中指定完整路径?

还是pdf引擎能够像浏览器一样提取图像?

我有以下 html 发送给转换器:

相关片段……

<div class="span12">

<img src="AccessPoint.aspx?action=Report.EditRecord.Start&html=TestUpload.html&script=Show&no_transaction=true&fileid=69">

<img src="images/imgWordDoc.gif">

</div>

我使用以下代码生成pdf:

                 // byte[] pdfBytes = pdfConverter.GetPdfBytesFromHtmlString(html.ToString());

                 // send the PDF document as a response to the browser for download        



                 //response.AddHeader("Content-Type", "binary/octet-stream");

                 string strFileName = "PrintToPDF.pdf";

                 if (template_defaults["PDF_REPORT_NAME"] != null)

                       strFileName = template_defaults["PDF_REPORT_NAME"].ToString() + ".pdf";



                 response.AddHeader("Content-Disposition",

                       "attachment; filename=" + strFileName + ";size=" + pdfBytes.Length.ToString());

                 response.ContentType = "application/pdf";

                 response.Flush();

                 response.BinaryWrite(pdfBytes);

                 m_error_log.WriteLine("pdf html = " + html.ToString(), iErrorLog.TITLE2);

                 response.Flush();
4

1 回答 1

2

来自http://www.evopdf.com/support.aspx

问:当我将 HTML 字符串转换为 PDF 时,外部 CSS 文件和图像不会应用到呈现的 PDF 文档中。

答:当您通过相对 URL 转换引用外部 CSS 文件和图像的 HTML 字符串时,转换器无法确定完整的 URL。为了解决这个问题,您必须使用从其中检索 HTML 字符串的页面的完整 URL 设置 HTML 字符串转换方法的 baseURL 参数。作为替代方案,您可以手动在 HTML 页面的 HEAD 标记中插入 BASE 标记,如下例所示,或者在 HTML 字符串中使用完整的 URL:

          <HEAD> <BASE HREF="SiteURL"> </HEAD>

这对我有用。如果图像带有href="../Images/Footer.png",我添加了一个

<base href="https:// mysite .com/Images/" />

(没有空格)

于 2015-02-18T14:59:16.607 回答