Home >Backend Development >PHP Tutorial >How to Convert PDF to JPEG with High Quality and Preserve Original Size?

How to Convert PDF to JPEG with High Quality and Preserve Original Size?

Patricia Arquette
Patricia ArquetteOriginal
2024-10-27 05:23:03750browse

 How to Convert PDF to JPEG with High Quality and Preserve Original Size?

Converting PDF to JPEG: Achieving High Quality and Preserving Original Size

For PDF conversion, scripts using ImageMagick may produce images with poor quality. Here's a solution to enhance quality and maintain the original PDF size.

The original script:

<code class="php">$im = new imagick( 'document.pdf[ 0]' ); 
$im->setImageColorspace(255); 
$im->setResolution(300, 300);
$im->setCompressionQuality(95); 
$im->setImageFormat('jpeg'); 
$im->writeImage('thumb.jpg'); 
$im->clear(); 
$im->destroy();</code>

To improve quality and maintain size:

<code class="php">// Instantiate Imagick
$im = new Imagick();

$im->setResolution(300, 300);
$im->readimage('document.pdf[0]');
$im->setImageFormat('jpeg');
$im->writeImage('thumb.jpg');
$im->clear();
$im->destroy();</code>

By setting the resolution before loading the PDF, you preserve the original size and improve image quality. ImageMagick's built-in settings may lead to cropping and size alteration. This modified script ensures faithful conversion while maintaining high quality.

The above is the detailed content of How to Convert PDF to JPEG with High Quality and Preserve Original Size?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn