Giter Site home page Giter Site logo

pdf-to-image's Introduction

@pdf-to-image

pdf-to-image provides a convenient interface for converting PDF to JPEG/PNG using Ghostscript.

Requirements

  • PHP version 7.4

Installation

Before using pdf-to-image, ensure that you have Ghostscript on your system:

sudo apt-get install ghostscript

Options

Options is an associative array with option as key and default as value.

Option Default Description
resolution 300 Resolution (dots per inch) of the generated images.
compression_quality 100 Compression quality for JPEG images (applies only to JPEG output).
alpha_bits 4 Number of bits (between 1 to 4) for alpha channel transparency in PNG images.
disable_color_management true Disable color management during PDF conversion.
disable_font true Disable font inclusion in the generated images.
disable_annotations true Disable annotations in the PDF during conversion.

Functions

These functions are ordered in use-case. From reading the file, to configure the conversion, to processing the PDF to JPG or PNG.

set_path(path)

Set the path to the Ghostscript executable:

$pdf_to_image->set_path(path);
  • path: relative or real path to the Ghostscript executable.

read(path)

Set a PDF to be read and converted. Referenced as path:

$pdf_to_image->read(path);
  • path: relative or real path to the PDF file.

set_configuration(options)

Configure the conversion process for the PDF:

$pti->set_configuration(options);

process(directory, type)

Convert to type which can either be JPG or PNG the given directory:

$pdf_to_image->process(directory, type);
  • directory: the directory in which the resulting conversions should be outputted.
  • type: specifies the file format for the conversion, either JPG or PNG.

Additional Functions

get_command(options)

Get the Ghostscript command for processing the PDF file:

$pdf_to_image->get_command(options);
  • options: options passed through get_command overwrites current and default configurations and parameters. See options.

get_page_amount(path)

Retrieve the amount of pages in a PDF:

$pdf_to_image->get_page_amount(path);
  • path: relative or real path to the PDF file.

Additional Notes

  • The example assumes that the Ghostscript executables are in the system's PATH variables.
  • Make sure the web server has the necessary permissions to read the input PDF file and write to the output directory.
  • Ensure that the proc_open function is not disabled in your PHP configuration. Check the disable_functions directive in your php.ini file and remove proc_open if present.
  • Ensure that the -dNumRenderingThreads parameter within the standard_command_parameters property of the PdfToImage class is set to the desired number of CPU cores.

pdf-to-image's People

Contributors

echtejosh avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.