Reputation: 11
If the image src attribute refers to image folder then it gets rendered in the pdf file. If the src attribute refers to an internal url then the image is not rendered. The other image is stored in the database that is why I need to specify the url.
Do I need to specify the complete path in the src attribute of the image?
Or the pdf engine will be able to extract the image like the browser is able to?
I have the following html which I send to the converter:
Relevant Snippet….
<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>
I use the following code to generate the 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();
Upvotes: 0
Views: 3362
Reputation: 334
From http://www.evopdf.com/support.aspx:
Q: When I convert a HTML string to PDF, the external CSS files and images are not applied in the rendered PDF document.
A: When you convert a HTML string referencing external CSS files and images by relative URLs, the converter cannot determine the full URLs. In order to solve this you have to set the baseURL parameter of the HTML string conversion method with the full URL of the page from where you have retrieved the HTML string. As an alternative you can manually insert a BASE tag in the HEAD tag of the HTML page as in the example below or use full URLs in the HTML string:
<HEAD> <BASE HREF="SiteURL"> </HEAD>
This works for me.
If images are with href="../Images/Footer.png"
, I added a
<base href="https:// mysite .com/Images/" />
(without spaces)
Upvotes: 2