Closed karlpatrickespiritu closed 2 years ago
You need to add 'isRemoteEnabled' => true
Sample
return PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true])->loadView('reports.invoiceSell')->stream();
@aodzylp It doesn't help, form me :disappointed:
this worked for me: <img src="http://www.domain.com/path/to/image/image.png" />
I get the same message when i print an image to pdf using laravel. Can you show a sample code of how to print an image to pdf.
Enabling remote by setting options helped me fix this. ... $html = ''; $options = new Options(); $options->setIsRemoteEnabled(true); $dompdf = new Dompdf($options); $dompdf->loadHtml($html); $dompdf->output(); ...
I solved it after changed to this:
<img src="{{ base_path() }}/location/to/image/image.png" />
@noriega9807 is right. I used <img src="{{ url('/images/image.png') }}">
and it worked fine.
Seems that it does not work in the local domain. it worked fine in the public domain.
I think it doesn't work when you customize options in any way.
laravel-dompdf
defines a set of default options in config/dompdf.php
. Whenever you customize these options either through setOptions
method or a custom dompdf.php
config file, all the defaults are ignored. Most likely some of the defaults are responsible for proper handling of images.
If this is true, then the issue can be solved by changing the behavior of the library to append-merge new options to the defaults.
If you still have problem with it. It might be due to something with ssl certificate, I just install one and the images stop showing.
To fix it:
$contxt = stream_context_create([
'ssl' => [
'verify_peer' => FALSE,
'verify_peer_name' => FALSE,
'allow_self_signed'=> TRUE
]
]);
$pdf = PDF::setOptions(['isHtml5ParserEnabled' => true, 'isRemoteEnabled' => true]);
$pdf->getDomPDF()->setHttpContext($contxt);
Got The issue if there are spaces in the image name or URL's
So replace the image-name with %20 it will be solved
$image = str_replace(' ', '%20', $items->image);
run it on htdocs. don't run using composer php artisan serve and give currect path url("/public/foldername/image.png").
I experience the problem intermittently. Some images render perfectly, some do not. And the ones that do will then not work in a few days time and the ones that don't will work.
I'm pretty certain I have narrowed down the problem. The images use a Shared Access Signature and the signature component of the SAS can include + signs (urlencoded to %2B). Every time an image doesn't render, I have found the signature has included a %2B which must be being converted to either a + or a space before accessing the img src url.
A solution would be very much appreciated.
Solved with the allow remote. Fun fact is that some images from remote were still rendering correctly due to the pagespeed mod on apache2 which was caching the data. I narrowed down the issue after disabling all my cache mods.
I also was on an older version of dompdf (really old project and no time to refractor)
Solution: Convert the image to base64
<img src=""data:image/png;base64, iVBORw0....." />
'isRemoteEnabled' => true
Worked for me..thanks aodzylp
I used @josesotomayor suggest. I created a custom class with the method that gets the base64.
`<?php namespace App\Custom;
class Archivos { public static function imagenABase64($ruta_relativa_al_public) { $path = $ruta_relativa_al_public; $type = pathinfo($path, PATHINFO_EXTENSION); $data = \File::get($path);
$base64 = "";
if ($type == "svg") {
$base64 = "data:image/svg+xml;base64,".base64_encode($data);
} else {
$base64 = "data:image/". $type .";base64,".base64_encode($data);
}
return $base64;
}
}`
Then in the view i did this.
@php use App\Custom\Archivos; @endphp <img src="{{Archivos::imagenABase64('assets/img/logo_empresa_contrato.jpg')}}" width="200px" >
`I've been having this problem for 3 days now, cant show image on pdf(used dompdf),i just wanna fetch the image locally using XAMPP on MAC, the image (goku.jpg) is located inside htdocs/images folder, already set the options, i guess the problem is with the path on src, tried everypath but still doesnt show, tried everything online but nothing seems to work.please help
`<?php
require("config.inc.php"); // Include autoloader require_once 'dompdf/autoload.inc.php'; // $_dompdf_show_warnings = true; // $_dompdf_warnings = [];
use Dompdf\Dompdf; use Dompdf\Options; //if posted data is not empty $options = new Options(); $options->set('defaultFont', 'Courier'); $options->set('isRemoteEnabled', TRUE); $options->set('debugKeepTemp', TRUE); $options->set('isHtml5ParserEnabled', TRUE); $options->set('chroot', '/'); $options->setIsRemoteEnabled(true);
$dompdf = new Dompdf($options); $dompdf->set_option('isRemoteEnabled', TRUE);
$auth = base64_encode("username:password");
$context = stream_context_create(array( 'ssl' => array( 'verify_peer' => FALSE, 'verify_peer_name' => FALSE, 'allow_self_signed'=> TRUE ), 'http' => array( 'header' => "Authorization: Basic $auth" ) ));
$dompdf->setHttpContext($context);
$agent = "Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)"; ini_set('user_agent', $agent);
if (isset($_GET['firstName'])){
$fileName = "https://i.ytimg.com/vi/1z3MA54hRW4/maxresdefault.jpg";
$root ='file:///kabushikikaishahaimessodo'. $_SERVER["DOCUMENT_ROOT"];
//$root = realpath(__DIR__);
$tempDir = $root.'/images/';
$fileName = 'goku.jpg'; $pngAbsoluteFilePath = $tempDir.$fileName;
$output = "
Name | Address | Contact number | Primary Key |
After updating the version to
0.7.0
. The images (.png) are broken ("Image not found or type unknown").