Hi may I know on how to add an image in pdf export file. I try to used code below but the image cannot be found. I place the image in images folder.// Page Exporting event
// $this->ExportDoc = export document object
function Page_Exporting()
{
global $basePath;
$basePath = BasePath(true);
$this->ExportDoc->Text .= “
”;
return true; // Return true to use default export and skip Row_Export event
}this coding I place it at View Page - Page_Exporting
I was struggling with this too. My uploads folder is outside (above) web root for security reasons, and I have file path encryption turned on.PDF exports had the image missing no matter what I did.
As soon as I moved the image into a location within web root and referenced that, the images were displayed.
Can I assume that ExportPDF is not able to pull images from outside (above) web root?
I made some progress, in that encrypted images are now showing.The problem is that I want an image from one of the fields to be shown in the header. File path is encrypted and I did a var dump and it looks like [“HrefValue”] is what I need.I printed $this->myfield->HrefValue to check the URL, AND I can even click on the link it made in the pdf and the image opens. But I can only get the URL in the footer, I guess as the value is generated after the header.However, the image still fails to display in the pdf - I wonder is it because dompdf can’t recognise it as an image due to there being no file extension?
That wouldn’t make much sense as the images which are part of my tables do show.I now also managed to get non-encrypted images to show, but not with relative path.
It only works when I use the full path including domain with private $isRemoteEnabled = true; set in dompdf options which isn’t very secure.How can I get get both encrypted path and relative path images to display?
because the images are stored one level higher than site root, and are not accessible directly by URL. Yes the image is embedded in the PDF because its in the table, but I only added it to the table to get the var dump so I could try to figure out how to call the image from an encrypted path…
Its a passport style photo, and I want it above the tables along with name and other essential details in larger format. Everything else is fine apart from getting an encrypted photo to show. For now I have copied all the photos to a folder within site root and I’m using the full URL, so it’s at least working now. But I really would rather not do that.
upload path is set to ** …/uploads/**
upload folder physical location is /var/www/uploads/,
site is root is at /var/www/html/
upload path for the field is “…/uploads/”.getSchoolID().“/StudentPhotos/”
uploads are working fine and into the right folder
I’m not using backslashes anywhereI’m using Page_Exporting to format the pdf header, and as I said its fine apart from the encrypted photos.
I just tried adding the photo using $this->Photo->HrefValue to an img tag in Page_DataRendering and it works to the page, but doesn’t show in the pdf
Assume your getSchoolID() works correctly in export mode, then using the path “…/uploads/xxx/StudentPhotos/yourimage.png” in your HTML for export to PDF should work (for v2022). You better turn on Debug and log your built image path for debugging.
Yes getSchoolID() works. I use it throughout the entire site. The path you gave doesn’t won’t work as my uploads folder is outside my site root, the browser cannot traverse to it. Debug didn’t show anything at all relating to the building of the URL even after adding Log(“Page Exporting”) to the function. Though I echoed the URL in the PDF, and it shows as a relative path, all correct except that it can’t be accessed due to it being outside root.I had to modify ExportPdf.php so that detail table headings would show in the exported PDFs (IMO they should be shown by default)ExportPdf
Is it possible to set this option in Global Code ?
Or do I have to manually edit options.php in dompdf/src folder?Just trying to avoid accidentally overwriting itif i set $chroot =“/my/path” in dompdf options i get this error:src/ExportPdf.php(130): Undefined constant "Dompdf\enabled"line 130 is:
$options = new \Dompdf\Options(self::$Options);
I couldn’t figure this out, for now I’m using a subfolder within the the site root, but still looking for a solution.
There is a static property Options in the ExportPdf class, you may get the options by, e.g. new \Dompdf\Options(ExportPdf::$Options), and get/set chroot by the getChroot() and setChroot() methods, see dompdf Options.php.
But how can I override $options->setChroot([‘/var/www/uploads/’]); ?
I’d like to be able to drop this into a switch in Gobal Code based on IP address, so that I don’t have to manually edit ExportPdf.php