If you use a program circulating on the Internet to implement the pdf file as png, you need to use the Imagic extension to install it in windows and then prompt:
Fatal error: Trying to clone an uncloneable object of class Imagick in C: \ www \ hx \ pai_to_png.php on line 17
This prompt is displayed when IIS and Apache are used. After multiple tests, we found two solutions:
1. in php. ini; Enable compatibility mode with Zend Engine 1 (PHP 4.x)
Zend. zemo-compatibility_mode = Off
The default value is On. after the value is changed to Off, the problem can be solved.
2. use imagick:... to call this method.
That is, $ im-> setResolution (120,120); can be rewritten:
Imagick: setResolution (120,120 );
If this type of error occurs for other extensions, you can use these two methods.
The code snippet for converting pdf to png:
The code is as follows:
Function ready 2png ($ pdf, $ filename, $ page = 0 ){
If (! Extension_loaded ('imagick ')){
Exit ('No imagick ');
Return false;
}
If (! File_exists ($ pdf )){
Return false;
}
$ Im = new Imagick ();
$ Im-> setResolution (120,120 );
$ Im-> setCompressionQuality (100 );
$ Im-> readImage ($ pdf. "[". $ page. "]");
$ Im-> setImageFormat ('PNG ');
$ Im-> writeImage ($ filename );
$ Im-> readImage ($ filename );
$ Im-> resizeImage (120,150, Imagick: FILTER_LANCZOS, 1 );
$ Im-> writeImage ($ filename );
Return $ filename;
}