PHP code example of imal-h / pdf-box

1. Go to this page and download the library: Download imal-h/pdf-box 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/ */

    

imal-h / pdf-box example snippets



$pdflib = new ImalH\PDFLib\PDFLib();
$pdflib->setPdfPath($pdf_file_path);
$pdflib->setOutputPath($folder_path_for_images);
$pdflib->setImageFormat(\ImalH\PDFLib\PDFLib::$IMAGE_FORMAT_PNG);
$pdflib->setDPI(300);
$pdflib->setPageRange(1,$pdflib->getNumberOfPages());
$pdflib->setFilePrefix('page-'); // Optional
$pdflib->convert();



$files = (new ImalH\PDFLib\PDFLib())
    ->setPdfPath($pdf_file_path)
    ->setOutputPath($folder_path_for_images)
    ->setImageFormat(\ImalH\PDFLib\PDFLib::$IMAGE_FORMAT_PNG)
    ->setDPI(300)
    ->setPageRange(1,$pdflib->getNumberOfPages())
    ->setFilePrefix('page-') // Optional
    ->convert();



$pdflib = new ImalH\PDFLib\PDFLib();
$imagePaths = ["images-1.jpg","images-2.jpg"];
$pdflib->makePDF($destination_pdf_file_path,$imagePaths);



$pdfBox->getNumberOfPages(); //returns the number of pages in the pdf
$pdfBox->setPageRange(1,2); // allows you to convert only few pages in the PDF Document
$pdfBox->setImageQuality(95); // allows you to tell the quality you expect in the output Jpg file (only jpg)
$pdfBox->setDPI(300); //setting the DPI (Dots per inch) of output files
$pdfLib->setImageFormat(\ImalH\PDFLib\PDFLib::$IMAGE_FORMAT_PNG,$dDownScaleFactor=null);   //this will set the output image format, default it is jpg, but I recommend using pdf to png because it seems it is faster
/*
$dDownScaleFactor=integer
This causes the internal rendering to be scaled down by the given (integer <= 8) factor before being output. For example, the following will produce a 200dpi output png from a 600dpi internal rendering:
    
    gs -sDEVICE=png16m -r600 -dDownScaleFactor=3 -o tiger.png\examples/tiger.png

Read More : http://ghostscript.com/doc/current/Devices.htm
*/