htmlpowershellpdfwkhtmltoimage

Export HTML to PDF with Images


I have created a HTML document from SQL in powershell. Now, when I attempt to export the HTML document to PDF with wkhtmltopdf, none of the images from the HTML document show up. If I were to create a PDF from google, the images will export just fine:

    $html = "https://www.google.com"
    $pdf  = "c:\temp\googletest.pdf"
    & "C:\Windows\wkhtmltopdf\bin\wkhtmltopdf.exe" $html $pdf | Out-Null

If I try to do it from the local HTML document, no images come across:

$html = "file:///C:/Temp/htmltest.htm"
$pdf  = "c:\temp\test.pdf"
& "C:\Windows\wkhtmltopdf\bin\wkhtmltopdf.exe" $html $pdf | Out-Null

What am I doing wrong?


Solution

  • Without having seen your local HTML...

    You could try using a fully-qualified Windows URI in your image source (notice the tripple /).

    <img src="file:///C:/path/to/your-image.jpg">