I want to display PDF files like image files on my WebPage on Apache2.4 on PHP7 in Windows 2008 Server, but I'm having the next error:
Fatal error: Uncaught ImagickException: PDFDelegateFailed
I already have installet ImageMagick-7.0.8-Q16 and Ghostscript 9.27 (32 bits) I replace Ghostcript 9.27 - 64 bits because the Apache Server shutdown inmediatly and restart. Here I found this note here: PHP: Uncaught ImagickException: PDFDelegateFailed .
On Command Line window:
If I run magick file.pdf file.jpg it's work.
If I run magick -verbose file.pdf file.jpg it's work and i see that it's using gswin32c.exe.
I have the same WebPage on my computer with Win10 Pro, same Imagick version, same ghostscript version, same Apache version, same PHP version and it's working fine.
$pdfInfo = new Spatie\PdfToImage\Pdf($file);
while ($page < $pdfInfo->getNumberOfPages()) {
$imagick = new Imagick();
$imagick->setResolution(100, 100);
$imagick->readImage(sprintf('%s[%s]', $file, $page));
echo sprintf('<img src="data:image/%s;base64,%s" ><br>', $type, base64_encode($imagick));
$page++;
The problem was the Ghostscript version. I had to replace the gs executable file from the Ghostscript page for the last version and it works fine.
Related
I have a problem moving my script from one server to one other.
The PHP script read a PDF file and create an image for each page of the pdf.
This script currently works in an environment that has these characteristics
PHP version: 7.4.8
Imagick version: 3.4.4
Now I have moved the script to an environment that has these characteristics:
PHP version: 7.4.28
Imagick version: 3.7.0
The code is:
$img = new Imagick($percorsoBaseDir); //LINE OF THE ERROR
$img->setResolution(600, 600);
$num_pages = $img->getNumberImages();
$img->setImageCompressionQuality(100);
$images = NULL;
for ($i; $i < $num_pages; $i++)
{
..... [My script] ....
}
And the error is:
AH01071: Got error 'PHP message: PHP Fatal error: Uncaught ImagickException: Failed to read the file in /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/custom_plugin/includes/woocommerce/Step_2.php:222\nStack trace:\n#0 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/custom_plugin/includes/woocommerce/Step_2.php(222): Imagick->readImage()\n#1 /var/www/vhosts/mysite.com/httpdocs/wp-includes/shortcodes.php(356): step_2_function()\n#2 [internal function]: do_shortcode_tag()\n#3 /var/www/vhosts/mysite.com/httpdocs/wp-includes/shortcodes.php(228): preg_replace_callback()\n#4 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/helpers/helpers.php(247): do_shortcode()\n#5 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/templates/shortcodes/vc_column_text.php(31): wpb_js_remove_wpautop()\n#6 /var/www/vhosts/mysite.com/httpdocs/wp-content/plugins/js_composer/include/classes/shortcodes/core/class-wpbakeryshortcode.php(451): require('/var/www/...',
I also tried throwing:
getcwd() //to verify that the file exists
and:
is_readable ($ pathBaseDir) //to verify that the file exist and is readable
is_writable ($ pathBaseDir) //to verify that the file exist and is writable
and they both return TRUE.
I also checked that the file loaded correctly in the file system and that I could open it from the browser.
I can't understand what can be the error, has something similar happened to you? How could I solve?
Thank you!
I find the problem: I have installed the Ghost Script in my server with this command:
apt-get install ghostscript
And now it works!
I have trouble using simpliest PHP (php version 7.4, XAMPP environment) code for image resize, with ImageMagick. It causes Apache server error The connection was reset (ERR_CONNECTION_RESET).
Here is code:
<?php
function resizeImage($imagePath) {
$imagick = new \Imagick(realpath($imagePath));
$imagick->resizeImage(320,240, \Imagick::FILTER_LANCZOS,1); // trouble line
header("Content-Type: image/jpg");
echo $imagick->getImageBlob();
//$imagick->writeImage("./output.png");
exit;
}
$imagePath = '/xampp/htdocs/devel/images/tumb500.jpg';
resizeImage($imagePath);
?>
Update:
Error in Apache logs related to this is:
PHP Warning: Version warning: Imagick was compiled against ImageMagick version 1799 but version 1803 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
But - checked and I have same error on other server where this code work properly.
And also, I tried with different (older) versions of ImageMagick and I have same error all the time.
Also to mention that other Imagick methods work properly.
Can you help me what I'm doing wrong here?
when using imagick to count the page number of pdf file it shows the error. PDFDelegateFailed `The system cannot find the file specified.' # error/pdf.c/ReadPDFImage/801 error is showing.Iam using Xampp server and i installed ghost script to resolve this error my apache stops working.
$image = new Imagick();
$image->pingImage($path);
echo $image->getNumberImages();
I'm running PHP 5.4.30 with imagick module 3.1.0RC2. phpinfo() does show the module as loaded and phpinfo() shows PDF as a supported format.
When running:
$image = new Imagick();
$image->readImage('./test.pdf');
I receive:
Fatal error: Uncaught exception 'ImagickException' with message 'Unable to read the file: ./test.pdf'
When I change the image type to be a JPEG and read './test.jpg' No errors are returned. Permissions have been check and different PDFs have been tested. I have inserted the absolute path to the image with an exception still being thrown. The images are for this example placed in the same directory alongside the script.
What am I missing?
I had the exact same problem. As command line it worked perfectly fine: convert book.pdf book.jpeg but pdf didn't seem to work. If not, you may want to install GhostScript
I found the solution on the issue 588918. You simply have to create a symlink of gs (the GhostScript library) in usr/bin. Basically, If you do something like
sudo ln -s /usr/local/bin/gs-noX11 /usr/bin/gs
and restart your server it should work. At least it did for me.
I have been trying to convert an html page to PDF with out any luck, I have tried to use wkhtmltopdf (http://code.google.com/p/wkhtmltopdf/) and the PHP class provided by the same developers (http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp) although the following command executed correctly in terminal:
wkhtmltopdf http:/www.googl.com test.pdf
I was unable to execute the command in PHP because of the following error:
cannot connect to X server.
Can any one provide me with a step-by-step tutorial in order to be able to convert html/css to PDF file, whether using wkhtmltopdf or any other decent solution.
Thanks in advance
here is the class that i have used http://code.google.com/p/wkhtmltopdf/wiki/IntegrationWithPhp
and below is my code
$html = file_get_contents("test.html");
$pdf = new WKPDF();
$pdf->set_html($html);
$pdf->render();
$pdf->output(WKPDF::$PDF_EMBEDDED,'sample.pdf');
Below is the error:
Fatal error: Uncaught exception 'Exception' with message 'WKPDF didn't return any data.
/usr/bin/wkhtmltopdf: /opt/lampp/lib/libxml2.so.2: no version information available
(required by /usr/lib/libgstreamer-0.10.so.0) No protocol specified wkhtmltopdf: cannot
connect to X server :0 </pre>' in /var/www/c4/components/com_wkhtmltopdf
/wkhtmltopdf.class.php:211 Stack trace: #0 /var/www/c4/components/com_wkhtmltopdf
/wkhtmltopdf.php(68): WKPDF->render() #1 /var/www/c4/components/com_wkhtmltopdf
/wkhtmltopdf.php(50): html2pdf() #2 /var/www/c4/index2.php(114): require_once('/var/ww...')
#3 {main} thrown in /var/www/c4/components/com_wkhtmltopdf/wkhtmltopdf.class.php on line 211
I found the solution, The following error "No protocol specified wkhtmltopdf: cannot
connect to X server :0" was basically caused by on old version of "wkhtmltopdf" which was installed using apt-get. The solution was to download the static binary from the code.google using the following link:
http://code.google.com/p/wkhtmltopdf/downloads/list
and then perform the following actions:
tar -jxvf wkhtmltopdf-0.11.0-static.tar.bz2
sudo aptitude install ia32-libs
Next, you’ll have to make a symbolic link pointing to WKHTMLTOPDF in /usr/bin.
sudo ln -s /full_path/WKHTMLTOPDF /usr/bin/WKHTMLTOPDF