2017 © Pedro Peláez
 

library electron-pdf-php

A PHP wrapper for electron-pdf

image

silvioiannone/electron-pdf-php

A PHP wrapper for electron-pdf

  • Friday, July 6, 2018
  • by silvioiannone
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 114 % Grown

The README.md

Introduction

electron-pdf-php is a PHP wrapper of electron-pdf. It simply provides a PHP interface for the electron-pdf cli tool., (*1)

Requirements

  • Linux or MacOS
  • Electron PDF

Installation

First install electron-pdf globally:, (*2)

npm install -g electron-pdf

Require electron-pdf-php using composer:, (*3)

composer require silvioiannone/electron-pdf-php

Usage

Usage is super easy:, (*4)

$generator = new SI\ElectronPdfPhp\Generator();
$pdf = $generator->fromHtml($html)
    ->content();

Settings

When instantiating a new generator instance the following settings may be passed to the constructor:, (*5)

  • executable => string - Path to the electron-pdf executable. Default: 'electron-pdf'
  • proxyWithNode => bool - Execute the command using node. This may be necessary in some cases where the error env: node: command not found is thrown. Default: false
  • graphicalEnvironment => bool - Whether the server has a graphical environment. This is only valid on Linux machines that have Xvfb installed. Default: false
  • marginsType => int - Specify the type of margins to use:
    • 0: default margins
    • 1: no margins (electron-pdf default setting)
    • 2: minimum margins

Example:, (*6)

$generator = new SI\ElectronPdfPhp\Generator([
    'executable' => '/usr/local/bin/electron-pdf'
    ...
]);

Specify a source

Generate a PDF from a URL:, (*7)

// Generate the PDF from a URL
$pdf = $generator->from('http://google.com')
    ->content();

Generate a PDF from HTML:, (*8)

// Generate the PDF from HTML
$pdf = $generator->fromHtml('<h1>Test<h1>')
    ->content();

Specify a destination

Save the PDF to a file:, (*9)

$generator->from('http://google.com')
    ->to('/home/downloads/test.pdf');

Get the PDF contents:, (*10)

$pdf = $generator->from('http://google.com')
    ->content();

The Versions

06/07 2018

dev-master

9999999-dev

A PHP wrapper for electron-pdf

  Sources   Download

MIT

The Requires

 

by Silvio Iannone