I am using TCPDF to create dynamically generated pdf file . In my pdf file a image is generated based on user input and I want to add that image on my pdf file . Here is my code
$map_image = "example.com/wp-content/themes/example/map_image_leasing.php/?city=Calgary&suit_type=&min_area=&max_area=";
$pdf->Image ($map_image, 55, 19, '', '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
If i paste "example.com/wp-content/themes/example/map_image_leasing.php/?city=Calgary&suit_type=&min_area=&max_area=" this on my url this create image as I wanted , but If put this url , it doesn't work . It says Unable to get the size of the image
But if I put something like this
$map_image = '/wp-content/themes/v3/resources/images/public/logo_side.jpg';
It can generate pdf with that image successfully .
How can I solve it ?
I have visited the following stackoverflow link , but none of this came to any help
tcpdf working on localhost but not on my sever giving error TCPDF ERROR: [Image] Unable to get image:
cakephp tcpdf image error [Image] Unable to get image
TCPDF ERROR: [Image] Unable to get image
Solution. The first and most common solution, is to search on your code what is the line or code that is generating some output before TCPDF and remove it (mentioned methods as print_r, var_dump, echo etc).
$tcpdf = new TCPDF_TCPDF(); $img = file_get_contents(Mage::getBaseDir('media') . '/dhl/logo. jpg'); $PDF_HEADER_LOGO = $tcpdf->Image('@' . $img);//any image file.
"Unable to get the size of the image" is the first error in the Image function that TCPDF will throw if the file is unaccessible to both of those functions on the server. I've had this problem after a PLESK update (in 2020). TCPDF didn't accept urls anymore in its image functions. Also <img tags in the pdf views didn't work anymore.
Unable to get the size of the image is an error thrown if TCPDF can’t fetch the image when using an absolute path.
tcpdf working on localhost but not on my sever giving error TCPDF ERROR: [Image] Unable to get image: This might be due to filesize () failing to stat () the remote image file via the HTTP wrapper (since the wrapper doesn't support it).
This might be due to filesize () failing to stat () the remote image file via the HTTP wrapper (since the wrapper doesn't support it). According to the TCPDF image () method documentation you can pass the image data in directly by prepending it with an @ symbol. So you could get the raw image data and then pass it to TCPDF like so:
This might be due to filesize()
failing to stat()
the remote image file via the HTTP wrapper (since the wrapper doesn't support it).
According to the TCPDF image() method documentation you can pass the image data in directly by prepending it with an @
symbol. So you could get the raw image data and then pass it to TCPDF like so:
$img = file_get_contents('http://example.com/wp-content/themes/example/map_image_leasing.php/?city=Calgary&suit_type=&min_area=&max_area=');
$pdf->Image('@' . $img, 55, 19, '', '', 'JPG', '', 'T', false, 300, '', false, false, 0, false, false, false);
Note that I haven't tested this (and the TCPDF documentation is sparse) so you might need to experiment a little to get it to work correctly.
Edit:
This is a fully working example (on my PC). Use this to test if you can successfully retrieve the image and output the PDF to your browser. Of course you'll need to set a known valid path for the image!
<?php
require './tcpdf/tcpdf.php';
$pdf = new TCPDF();
$pdf->AddPage();
$img = file_get_contents('http://path/to/your.jpg');
$pdf->Image('@' . $img);
$pdf->Output();
?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With