Skip to content
ComPDF
DemoFAQ
New Release

Open-Source PDF SDK & AI Document Processing

Get the full self-hosted SDK and AI document processing on GitHub. One-click deploy to quickly build your document workflows.

Convert PDF to Image

Overview

ComPDF Conversion SDK provides an API for converting PDF to images. Integrate ComPDF Conversion SDK to your apps to convert PDF into images easily.

Setting Image Formats

In ComPDF Conversion SDK, supported image formats include:

  • JPG
  • JPEG
  • JPEG2000
  • PNG
  • BMP
  • TIFF
  • TGA
  • GIF
  • WEBP

Setting Image Color Modes

Supported image color modes in ComPDF Conversion SDK include:

  • Color (ImageColorMode::COLOR): Color mode, where the image effect is consistent with the original PDF page.
  • Gray (ImageColorMode::GRAY): Grayscale mode.
  • Binary (ImageColorMode::BINARY): Black and white mode, which applies binarization to the original effect.

Setting Image Scaling

The SDK supports setting image scaling. The default scaling is 1.0, which maintains the original PDF page size. If you want to double the image size, you can set imageScaling to 2.0; similarly, to reduce the image size by half, set imageScaling to 0.5.

Enhancing Image Path Display

The SDK supports an option called imagePathEnhance for enhancing the display of image paths. This option can be enabled when you want to enhance the display effect of paths within the PDF page.

Notice

  • A higher imageScaling value results in images with higher resolution, but it also increases memory usage and slows down the conversion.
  • A higher imageScaling value does not necessarily equate to higher clarity; the clarity also depends on the original image resolution in the document.

Sample

The following complete example code demonstrates how to convert a PDF document into PNG format.

php
use ComPDFKit\Conversion\ImageType;

$option = new ConvertOption();
// Convert PDF to Image (JPEG).
$option->imageType = ImageType::JPEG;
Conversion::convert('Image', 'jpeg.pdf', 'password', 'output_jpeg', $option);

// Convert PDF to Image (PNG) and set imageScaling to double the original PDF size.
$option->imageType = ImageType::PNG;
$option->imageScaling = 2.0;
Conversion::convert('Image', 'png.pdf', 'password', 'output_png', $option);