Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 40 Next »

The code snippet example will generate a simple pdf from the PDF service.

Code Snippet Example:

Build PDF
//to import the pdf service classes
$t->runInteraction("Pdf.class.php");
//import config class which contains keys
$t->runInteraction("Config.class.php");

//set header/footer keys
$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_thml
   ),
   "body" => array(
       "html" => $body
   )
);


echo "About to build<BR>";

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

echo "<pre>";
print_r($result);
echo "</pre>";

/*
 try {
print_r($result);
 } catch (Exception $e) {
      print_r($result);
 }
*/

//Following code sends an email to your email address with pdf as attachment
$t->addStringAttachment(file_get_contents($result["url"]), "Report.pdf", "base64");
$from = "bmp@blinkmobile.com.au";
$to = "YOUR ADDRESS EMAIL";
$subject = "[BlinkMobile] PDF Demo";
$body = "PDF Attached.";
$t->email($to, $subject, $body, $from);

return "Done<BR>";


/**
* $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.

new PDFBuilder
$pdf = new PDFBuilder(Config::$PDF);

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

$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.

 In the example above, we're including the two built in variables {_BLINK_PAGE_NO_}/{_BLINK_PAGES_} which will display the page number and total page numbers.

headerAn array containing your header styling and html code 
 

height : (array) use the same parameters as page:margin

 "height" => "1in" (default)
 

html : (string) containing your header html code

  "html" => $header_html


$footer_html (array)

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

 In the example above, we're including the two built in variables {_BLINK_PAGE_NO_}/{_BLINK_PAGES_} which will display the page number and total page numbers.

footerAn array containing your header styling and html code 
 

height : (array) use the same parameters as page:margin

 "height" => "1in" (default)
 

html : (string) containing your footer html code

 "html" => $footer_thml


$body (array)

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

bodyAn array containing your header styling and html code 
 

html : (string) containing your footer html code

     "html" => $body

$content (array)

The content array contains tall the parameters required to produce a PDF document.

Default Page Parametres
 "page": {
    "orientation": "P",
    "size": "A4",
    "margins": {
      "top": "5mm",
      "right": "1cm",
      "bottom": "5mm",
      "left": "1cm"
    }
pageAn array containing the following parameters 
 orientation : (string) page orientation.
  • P  or portrait (default).
  • L  or landscape

 

size : (string) page size

 

  • A3

  • A4 (default)

  • A5

  • Legal

  • Letter

  • Tabloid

 margins :  (array) for top, right, bottom and left margins (case sensitive)
  • "top": "5mm"
  • "right": "1cm"
  • "bottom": "5mm"
  • "left": "1cm"
 

margin-units - (string) User measure unit. Possible values are:


  • px: pixels (default)

  • mm: millimeter

  • cm: centimeter

  • in: inch
 header : an array containing the $header arraySee above
 footer : an array containing the $footer arraySee above
 body : an array containing the $body arraySee above

 

Blink Constants - (string) for page number and number of pages (only works in header and footer

 

  • {_BLINK_PAGES_} - total number of pages

  • {_BLINK_PAGE_NO_} - current page number

Response:

After running this method, you will receive a response object array that contains the PDF.

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





  • No labels