PHPackages                             vsitnikov/pdflib - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. vsitnikov/pdflib

ActiveLibrary

vsitnikov/pdflib
================

Current Release of PDFlib provide you methods to convert PDF to Images as well as Images to PDF.

1.3.1(6y ago)036MITPHPPHP &gt;=5.5.0

Since Sep 5Pushed 6y agoCompare

[ Source](https://github.com/sitnikovv/PDFLib)[ Packagist](https://packagist.org/packages/vsitnikov/pdflib)[ Docs](https://github.com/imalhasaranga/PDFLib.git)[ RSS](/packages/vsitnikov-pdflib/feed)WikiDiscussions master Synced 6d ago

READMEChangelogDependencies (2)Versions (10)Used By (0)

PDFlib 1.3.0
============

[](#pdflib-130)

PDFlib is a project which enables you to interact with PDFs, Current Release provide you methods to convert PDF to Images as well as Images to PDF, future releases will included more functions to interact with PDF files

This project is an initiative of [Treinetic (Pvt) Ltd](http://www.treinetic.com), Sri Lanka. contact us via  and get your project done by the experts.

[![Issues](https://camo.githubusercontent.com/3df44a900cc81c655fe601fa568c64f9b9fe579f1bd9d5e0629d3f693f3589bb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f696d616c6861736172616e67612f504446426f782e737667)](https://camo.githubusercontent.com/3df44a900cc81c655fe601fa568c64f9b9fe579f1bd9d5e0629d3f693f3589bb/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6973737565732f696d616c6861736172616e67612f504446426f782e737667)[![Software License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE.md)[![Forks](https://camo.githubusercontent.com/1c46be110826e77a15d036f846310a362f668e71ad2bcda06a7129590bf4f811/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f696d616c6861736172616e67612f504446426f782e737667)](https://camo.githubusercontent.com/1c46be110826e77a15d036f846310a362f668e71ad2bcda06a7129590bf4f811/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f696d616c6861736172616e67612f504446426f782e737667)

Requirements
------------

[](#requirements)

You should have [Ghostscript](http://www.ghostscript.com/) &gt;= 9.16 installed and configured.

Install
-------

[](#install)

The package can be installed via composer:

```
$ composer require vsitnikov/pdflib
```

Usage
-----

[](#usage)

Converting a PDF to set of images.

```
$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();
```

Alternatively using chaining:

```
$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();
```

Making a PDF from set of images

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

If in anycase code throws '\*\*\*\* Unable to open the initial device, quitting.' this type of error that means program can't create temporary files because of a permission problem, this error only comes in the Linux or Mac Oparating systems so Please check the apache log and provide necessay permissions

Other useful methods
--------------------

[](#other-useful-methods)

You can get the total number of pages in the pdf:

```
$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
