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
Release: 2024-10-27 05:23:03
Original
752 people have browsed it

 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>
Copy after login

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>
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template