PHP code example of adamroyle / php-xpdf

1. Go to this page and download the library: Download adamroyle/php-xpdf 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/ */

    

adamroyle / php-xpdf example snippets


$pdfToText = XPDF\PdfToText::create();

$pdfToText = XPDF\PdfToText::create(array(
    'pdftotext.binaries' => '/opt/local/xpdf/bin/pdftotext',
    'pdftotext.timeout' => 30, // timeout for the underlying process
), $logger);

$pdfToText = XPDF\PdfToText::create();
$text = $pdfToText->getText('document.pdf');

$text = $pdfToText->getText('document.pdf', $from = 1, $to = 4);

$pdfToText->setPageQuantity(2);
$pdfToText->getText('document.pdf'); // extracts page 1 and 2

$pdfImage = XPDF\PdfImage::create();
$pdfImage->setOutputFormat('jpeg');
$images = $pdfImage->getImages('document.pdf');

$pdfToPpm = XPDF\PdfToPpm::create();
$pdfToPpm->setOutputFormat('png');

// optional, set an output resolution
$pdfToPpm->setResolution(300); // default is 150

// alternatively, set the max width/height in pixels. this overrides the resolution setting.
// $pdfToPpm->setMaxDimension(2000);

$images = $pdfToPpm->getImages('document.pdf');