The code snippet example will generate a simple pdf from the PDF service.
Code Snippet Example:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
//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.
//create object
$analytics = new Event(Config::$ANALYTICS_COLLECTOR);
This line will simply create the $analytics object, using the details from the the Config.class.php file. You don't need to modify this line.
//register login event with username, returns saved event with unique id
$response = $analytics->log("Login", array("username" => "johnsmith", "group" => "Inspector"));
This line is the method that will log an event. In this example, you may want to call this after a user successfully logs in.
The $analytics->log method takes two arguments:
- The name of the event
- Extra data you wish to include
$name (string value)
In the code example above, the event is named "Login". This is can be any string, and you can name it whatever you wish.
This will allow you to group specific events together, and so later you could run an query to show all "Logins", or all "Form Submissions", for example.In the code example above, the event is named "new PDFBuilder".
Code Block | ||||
---|---|---|---|---|
| ||||
$pdf = new PDFBuilder(Config::$PDF); |
$tags (array)
The tags array can contain any extra information you want to include in this log. These are entirely freeform - you can include as much (within reason) or as little information in this array as you wish.
...