PHP code example of appkita / pdftoimage
1. Go to this page and download the library: Download appkita/pdftoimage library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
appkita / pdftoimage example snippets
$image = new Imagick();
$image->newImage(1, 1, new ImagickPixel('#ffffff'));
$image->setImageFormat('png');
$pngData = $image->getImagesBlob();
echo strpos($pngData, "\x89PNG\r\n\x1a\n") === 0 ? 'Ok' : 'Failed';
$file = '<<pdf file>>';
//or
$file = 'URL FILE';
//configuration
$option = [
'path' => '<<result path>>', //default empty
'format' => 'png', //set image format output
'resolution' => 'set resultion image',
'prefix'=> 'convert', //set prefix name image
'layer_method'=>Imagick::LAYERMETHOD_FLATTEN, //follow Imagick Layer Method
'colosrpace'=> null, //follow Imagick colorspace
'quality'=> null, //follow imagick result quality
];
$spesific_page = null;
$convert = new \Appkita\PDFtoImage\Convert($file, $option);
$result = $convert->run(); //set null if you wont
//or
$result = $convert->run($spesific_page);
/**
* Or
*/
$convert = new \Appkita\PDFtoImage\Convert($file);
$convert->path = '<<your path>>';
$convert->format = 'jpg';
$convert->run($spesific_page);
/**
* Or
*/
$convert = new \Appkita\PDFtoImage\Convert();
$result = $convert->setFile($filepdf)->run($spesific_page, $options); // if is_string $options return $path output
sh
sudo yum install php-imagick
php -m | grep imagick
sh
sudo apt-get install php-imagick
php -m | grep imagick