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:
//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); //Setting $includeBase64Content to true will include the PDF file content in the response object //Set to false to access the PDF file from a time limited URL instead $includeBase64Content = true; $result = $pdf->build($content, $includeBase64Content);
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.
$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.
header | An 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.
footer | An 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.
body | An 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.
"page": { "orientation": "P", "size": "A4", "margins": { "top": "5mm", "right": "1cm", "bottom": "5mm", "left": "1cm" }
page | An array containing the following parameters | |
---|---|---|
orientation : (string) page orientation. |
| |
size : (string) page size |
| |
margins : (array) for top, right, bottom and left margins (case sensitive) |
| |
margin-units - (string) User measure unit. Possible values are: |
| |
header : an array containing the $header array | See above | |
footer : an array containing the $footer array | See above | |
body : an array containing the $body array | See above |
Blink Constants - (string) for page number and number of pages (only works in header and footer
Parameters # | |
---|---|
{_BLINK_PAGES_} | A constant which when added to the header or footer array will display total number of pages |
{_BLINK_PAGE_NO_} | A constant which when added to the header or footer array will display the current page number |
Response:
After running this method, you will receive a response object array that contains the PDF.
$result = array( "id" => "<UNIQUE OBJECT ID>", "url" => "http://url.to.pdf/valid.for.3.minutes", content" => "base64 pdf content" }