Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The code snippet example will allow you to create a PDF file from HTML code that you pass to the PDF service. You will then be returned either a download link, or optionally the PDF file contents in the API response.

Code Snippet Example:


Code Block
languagephp
themeRDark
titleBuild PDF
//Import the pdf service classes
$t->runInteraction("Pdf.class.php");
$t->runInteraction("Config.class.php");

//Set header, footer, and page content HTML Code
//HTML5 and CSS3 is supported
$header_html = "{_BLINK_PAGE_NO_}/{_BLINK_PAGES_}<br><hr>";
$footer_html = "<hr><br>{_BLINK_PAGE_NO_}/{_BLINK_PAGES_}";
$body = "<table><td>PDF Example: " . date("c") . "</td></tr></table>";

$content = array(
   "page" => array(
       "orientation" => "Portrait",
       "size" => "A4",
       "margins" => array(
           "top" => "5mm",
           "right" => "1cm",
           "bottom" => "5mm",
           "left" => "1cm"
       )
   ),
   "header" => array(
       "height" => "1in",
       "html" => $header_html
   ),
   "footer" => array(
       "height" => "1in",
       "html" => $footer_html
   ),
   "body" => array(
       "html" => $body
   )
);


//Call the PDF Service
$pdf = new PDFBuilder(Config::$PDF);
//build pdf, if base64 is required
$result = $pdf->build($content);






/**
* $result = array(
*  "id" => "<UNIQUE OBJECT ID>",
*  "url" => "http://url.to.pdf/valid.for.3.minutes",
*  "content" => "base64 pdf content"
* );
**/

 

Explanation:

The first two "runInteraction" lines will simply "include" the class files you already uploaded. Make sure your have used the correct interaction names. You will need to put both of these lines on any page, or interaction, that you will be calling the class.

In the code example above, the following functions are used.

The function calls the PDF Service with your access credentials set up in the Config.class.php file and sends your PDF content to be created.

Code Block
languagephp
titlenew PDFBuilder
$pdf = new PDFBuilder(Config::$PDF);

Optional: You can include BMP mADL code to send you the results of the generated PDF via email. 

Code Block
languagephp
title$t->email
$t->email($to, $subject, $body, $from);

See more information on $t->email

$header_html (array)

The header array can contain any HTML code or CSS styling you want in the header section of your PDF document.

...