pdfapi/php-sdk

This package is abandoned and no longer maintained. No replacement package was suggested.

pdfapi.io enables HTML pages that can contain CSS and JavaScripts to generate beautiful PDF via API

v1.0.0 2016-11-05 14:21 UTC

This package is not auto-updated.

Last update: 2021-11-07 23:59:16 UTC


README

Build Status Coverage Status

pdfapi.io SDK for PHP

Installation

pdfapi.io PHP SDK can be installed with Composer. Run this command:

composer require pdfapi/php-sdk

Usage

Usage of pdfapi.io PHP SDK is very simple. The easyest way to get started is:

use PdfApi\PdfApi;

$template = <<<HTML
<!DOCTYPE html>
<html>
    <body>
        <h1>pdfapi.io makes PDF generation so easy.</h1>
        <p>And it can do complicated stuff.</p>
    </body>
</html>
HTML;

$pdfApi = new PdfApi('YOUR_API_KEY');
$pdfApi->setHtml($template);

$rawPdf = $pdfApi->generate();

Full example of the usage: Note: Be aware that header and footer are separate HTML documents (with styles and everything) that are copied to each page.

use PdfApi\PdfApi;
use PdfApi\Parameter\Enum\Orientation;
use PdfApi\Parameter\Enum\Size;

$template = <<<HTML
<!DOCTYPE html>
<html>
    <body>
        <h1>pdfapi.io makes PDF generation so easy.</h1>
        <p>And it can do complicated stuff.</p>
    </body>
</html>
HTML;

$header = <<<HTML
<!DOCTYPE html>
<html>
  <body>
      <p>pdfapi.io</p>
  </body>
</html>
HTML;

$footer = <<<HTML
<!DOCTYPE html>
<html>
  <body>
      <p>pdfapi.io</p>
  </body>
</html>
HTML;


$pdfApi = new PdfApi('YOUR_API_KEY');
$pdfApi->setHtml($template);
$pdfApi->setHeader($header);
$pdfApi->setFooter($footer);
$pdfApi->setSize(Size::A4);
$pdfApi->setOrientation(Orientation::Landscape);

$rawPdf = $pdfApi->generate();

//or optionally you can save PDF directly to file
$pdfApi->save('/path/to/file.pdf');

For getting API KEY you need to register account at https://pdfapi.io. Generating API KEY will take you 10 seconds. And it is free. Really.