Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add images to a PDF created with Nreco PdfGenrator

I'm using Nreco PDFGenerator to generate PDFs using the following PowerShell script:

$PdfGenerator = "$((Get-Location).Path)\lib\NReco.PdfGenerator.dll"
$Assembly = [Reflection.Assembly]::LoadFrom($PdfGenerator)
$PdfCreator = New-Object NReco.PdfGenerator.HtmlToPdfConverter

$PdfCreator.PageHeight = 297
$PdfCreator.PageWidth = 210
$PdfCreator.Zoom = 2
$pdfBytes = $PdfCreator.GeneratePdf([string](gc myhtml.htm))
Add-Content -Value $pdfBytes -Encoding byte -Path "./mypdf.pdf"

myhtml.htm is a simple HTML document:

<html>
  <head>
    <title>Hello World</title>
  <body>
    <img src='./img/FancyImage.jpg' alt='Fancy Image' />
  </body>
</html>

Everything looks perfectly fine, except that the images are missing...

Any ideas are welcome!

like image 870
Markus Avatar asked Sep 20 '25 01:09

Markus


1 Answers

Apperently, the answer was right on the projects website / FAQ:

It is possible to include images by specifying their FULL URL or path (if they're on local filesystem). External CSS and javascript files are also supported.

like image 93
Markus Avatar answered Sep 21 '25 16:09

Markus