SetaPDF Demos

There seems to be a problem loading the components. Please check your PHP error logs for details!

Common issues could be that you missed to install the trial license or that you are using a trial version on an unsupported PHP version.

Image to PDF with pre-defined resolution

This demo converts an image to a PDF document in a pre-defined resolution.

You will not see the difference in the reader application because the pixel density isn't changed in any way. The difference can be seen in the page properties - at the end it is the page size that changes relatively to the given resolution (that bigger the resolution, that smaler the page size will be).


// load and register the autoload function
require_once '../../../../../bootstrap.php';

// prepare some files
$files = [];
foreach (glob($assetsDirectory . '/images/*/*.{png,jpg,jpeg,gif}', GLOB_BRACE) as $file) {
    foreach ([72, 96, 150, 300] as $dpi) {
        $files[] = [
            'path' => $file,
            'displayValue' => basename($file) . ' (' . $dpi . 'dpi)',
            'dpi' => $dpi

$imgData = displayFiles($files, true);

// create a writer
$writer = new \SetaPDF_Core_Writer_Http('ImgInSpecificResolution.pdf', true);
// create a document
$document = new \SetaPDF_Core_Document($writer);

$img = \SetaPDF_Core_Image::getByPath($imgData['path']);
$xObject = $img->toXObject($document);
$width = $xObject->getWidth();
$height = $xObject->getHeight();

// calculate the width by the given DPI value
$dpi = $imgData['dpi'];

$width = $width * 72 / $dpi;
$height = $height * 72 / $dpi;

$pages = $document->getCatalog()->getPages();
$page = $pages->create(
    [$width, $height],
$canvas = $page->getCanvas();
$xObject->draw($canvas, 0, 0, $width, $height);