PHP code example of vsitnikov / pdflib

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

    

vsitnikov / pdflib example snippets



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



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



$pdflib = new vsitnikov\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(\vsitnikov\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
*/