2017 © Pedro Peláez
 

library pdfshift-php

Convert HTML documents to PDF using the PDFShift.io API.

image

pdfshift/pdfshift-php

Convert HTML documents to PDF using the PDFShift.io API.

  • Wednesday, June 13, 2018
  • by pdfshift
  • Repository
  • 2 Watchers
  • 2 Stars
  • 96 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

:warning: PDFShift's API being simple to implement and use, we realized that using a custom library just to wrap a network library was not necessary. As such, we decided to close this package and we recommend you to use a network library such as cURL to communicate with PDFShift., (*1)

PDFShift PHP Package

This PHP package provides a simplified way to interact with the PDFShift API., (*2)

Documentation

See the full documentation on PDFShift's documentation., (*3)

Requirements

PHP 5.4.0 and later., (*4)

Composer

You can install the bindings via Composer. Run the following command:, (*5)

composer require pdfshift/pdfshift-php

To use the bindings, use Composer's autoload:, (*6)

require_once('vendor/autoload.php');

Manual Installation

If you do not wish to use Composer, you can download the latest release. Then, to use the bindings, include the init.php file., (*7)

require_once('/path/to/pdfshift-php/init.php');

Usage

This library needs to be configured with your api_key received when creating an account. Setting it is easy as:, (*8)

\PDFShift\PDFShift::setApiKey('your_api_key');

Basic example

With an URL

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');
PDFShift::convertTo('https://www.example.com', null, 'result.pdf');

With inline HTML data:

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

$data = file_get_content('invoice.html');
PDFShift::convertTo(data, null, 'result.pdf');

Custom CSS

Loading CSS from an URL:

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

$data = file_get_content('invoice.html');
PDFShift::convertTo(data, ['css' => 'https://www.example.com/public/css/print.css'], 'result.pdf');

Loading CSS from a string:

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

$data = file_get_content('invoice.html');
PDFShift::convertTo(data, ['css' => 'a {text-decoration: underline; color: blue}'], 'result.pdf');

Custom HTTP Headers

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

// We use an instance of PDFShift instead of the ::convertTo to easily handle advanced configuration
$pdfshift = new PDFShift();
$pdfshift->setHTTPHeaders(['X-Original-Header' => 'Awesome value']);
$pdfshift->addHTTPHeader('user-agent', 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0'); // Also works like this
$pdfshift->convert('https://httpbin.org/headers');
$pdfshift->save('result.pdf');

Accessing secured pages

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

// We use an instance of PDFShift instead of the ::convertTo to easily handle advanced configuration
$pdfshift = new PDFShift();
$pdfshift->auth('user', 'passwd');
$pdfshift->convert('https://httpbin.org/basic-auth/user/passwd');
$pdfshift->save('result.pdf');

Using cookies

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

// We use an instance of PDFShift instead of the ::convertTo to easily handle advanced configuration
$pdfshift = new PDFShift();
$pdfshift->addCookie('session', '4cb496a8-a3eb-4a7e-a704-f993cb6a4dac');
$pdfshift->convert('https://httpbin.org/cookies');
$pdfshift->save('result.pdf');

Adding Watermark (Oh hi Mark!)

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

// We use an instance of PDFShift instead of the ::convertTo to easily handle advanced configuration
$pdfshift = new PDFShift();
$pdfshift->watermark([
    'image' => 'https://pdfshift.io/static/img/logo.png',
    'offset_x' => 50,
    'offset_y' => '100px',
    'rotate' => 45
])
$pdfshift->convert('https://www.example.com');
$pdfshift->save('result.pdf');
require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

// We use an instance of PDFShift instead of the ::convertTo to easily handle advanced configuration
$pdfshift = new PDFShift();
$pdfshift->setFooter('

Page {{page}} of {{total}}
', '50px'); $pdfshift->convert('https://www.example.com'); $pdfshift->save('result.pdf');

Protecting the generated PDF

require_once('vendor/autoload.php');
use \PDFShift\PDFShift;

PDFShift::setApiKey('your_api_key');

// We use an instance of PDFShift instead of the ::convertTo to easily handle advanced configuration
$pdfshift = new PDFShift();
$pdfshift->protect([
    'userPassword' => 'user',
    'ownerPassword' => 'owner',
    'noPrint' => true
]);
$pdfshift->convert('https://www.example.com');
$pdfshift->save('result.pdf');

Contributing

Please see CONTRIBUTING for details., (*9)

License

The MIT License (MIT). Please see License File for more information., (*10)

The Versions

13/06 2018

dev-master

9999999-dev https://github.com/pdfshift/pdfshift-php

Convert HTML documents to PDF using the PDFShift.io API.

  Sources   Download

MIT

The Requires

 

api html pdf convert document pdfshift

12/06 2018

v1.0.2

1.0.2.0 https://github.com/pdfshift/pdfshift-php

Convert HTML documents to PDF using the PDFShift.io API.

  Sources   Download

MIT

The Requires

 

api html pdf convert document pdfshift