Skip to content

Instantly share code, notes, and snippets.

@Initsogar
Last active December 15, 2015 12:09
Show Gist options
  • Save Initsogar/5258467 to your computer and use it in GitHub Desktop.
Save Initsogar/5258467 to your computer and use it in GitHub Desktop.
PHP-Client Pagify API Example
<?php
/**
* This is an Pagify API example using the PHP-Client (https://github.com/pagify/php-client).
* Generating a PDF using a template previously created.
*
* Assuming your pagifyio.php is in the same
* directory as this file.
*/
require_once 'pagifyio.php'
/**
* Initializing PagifyIO object with your auth keys
*/
$pagify = new PagifyIO(<COSTUMER_KEY>, <PRIVATE_KEY>);
/**
* Assuming we've 2 text fields...
*/
$data = array(
'text_field1' => 'Write some text here',
'text_field2' => 'Write another text here'
);
/**
* Generating a PDF from a template previously configured
* in alpha.pagify.io
*/
$response = $pagify->generatePDF(<TEMPLATE_ID>, $data);
/**
* Check if response is a binary or an object.
* - Binary = PDF File
* - Object = JSON Response
*/
if(is_object($response)){
/**
* Let's see what we've got here.
* It seems to be an error.
*/
print_r($response);
}
else{
/**
* If response is binary, we need to create
* a PDF File and write it contents with the
* response.
*/
$fp = fopen('test.pdf', 'w+');
fwrite($fp, $response);
fclose($fp);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment