PHP code example of pdfapi / php-sdk

1. Go to this page and download the library: Download pdfapi/php-sdk library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pdfapi / php-sdk example snippets



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


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');