Skip to content
Pagify client for PHP.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.project
README.md
pagifyio.php

README.md

Pagify Client for PHP

Pagify is a web-based document design and generation service, that integrates nicely with your existing web applications and SaaS products.

For further information on uses of Pagify, please visit http://pagify.io

This client library helps you to integrate Pagify with your PHP applications with minimum coding effort. Before using this library please ensure that you have a valid Pagify service account, and have noted down your API key and secret.

Install the library by first cloning the repository or downloading it as a tar ball. Then copy the pagifyio.php to your working directory, and ensure that the PHP Curl extension is enabled.

Using this library you can;

  • List existing document templates
  • Create a new document template
  • Delete a document template
  • Generate link to edit a document template
  • Generate PDF

Before calling any action or function make sure to initialize the client using your api secret and api key:

include_once 'pagifyio.php';

$pagify = new PagifyIO('<api-key>','<api-secret>');

Once initailized the pagify object can be used to perform all the above listed actions.

  1. List templates:

A list of all templates that have either been created using Pagify dashboard or through the public API can be retrieved through listTemplates call.

$templates = $pagify->listTemplates();

Here is a sample response for a successful call:

array (
  "statusCode" => 200, 
  "message" => "Here is the list of the templates.", 
  "templateIds" => array(
    "71d620fc773a11e288cce006e61619ba" => "First Template",
    "89afs89fff88s8s8f8cce006e61619ba" => "Second Template"
  )
)

The response contains a hash with template ids as keys and template names as values.

Note that the template id is unique whereas template name is not.

  1. Create template:

Create a blank templates using createTemplate function call.

$template = $pagify->createTemplate();

Here is a sample successful response:

array (
  "statusCode" => 200, 
  "message" => "Here is the template id of the new template.", 
  "templateId" => "71d620fc773a11e288cce006e61619ba"
)

The response contains the template id for the new template.

Note that this template is not ready to generate PDF as long as you don't edit and save it for the first time.

  1. Delete template:

To delete a template use deleteTemplate function call.

$template = $pagify->deleteTemplate(<template_id_as_string>);

For example if the template id is "71d620fc773a11e288cce006e61619ba"

$response = $pagify->deleteTemplate("71d620fc773a11e288cce006e61619ba");

On a successful call you should get following response:

array (
  "statusCode" => 200, 
  "message" => "Succesfully deleted the template."
)
  1. Edit template:

The API allows to generate a link to edit a specified template, without user actually logging in to Pagify service. The user must visit the link with 30 minutes time, otherwise the link will expire. Once the user visits the link the session validity increases upto 1 day. After that the developer must request a new link to edit the template. You can generate the link by calling editTemplate function

$template = $pagify->editTemplate(<template_id_as_string>);

For example

$template = $pagify->editTemplate("71d620fc773a11e288cce006e61619ba");

If the template is valid a typical successful response will be as follows:

array (
  "statusCode" => 200, 
  "url" => "http://pagify.io/templates/71d620fc773a11e288cce006e61619ba/edit?template_session=89afs89fff88s8s8f8cce006e61619ba"
)
  1. Generate PDF:

To generate a PDF use generatePDF function call. The function call requires a valid template id and data.

$template = pagify->generatePDF(<template_id_as_string>, <data_as_associative_array>);

For example

$data = array (
  "text_field" => "Hello World!",
  "image_field" => "http://abc.com/xyz.png",
  "chart_multi_value_field" => array(
    array("First", "Second", "Third"),
    array(20, 40, 30),
    array(50, 60, 10)
  ),
  "chart_single_value_field" => array(20, 30, 40),
  "chart_xy_field" => array(
    array(
      array("x" => 20, "y" => 40),
      array("x" => 10, "y" => 30),
      array("x" => 70, "y" => 50)
    ),
    array(
      array("x" => 10, "y" => 30),
      array("x" => 20, "y" => 30),
      array("x" => 80, "y" => 30)
    )
  )
);

$template = pagify->generatePDF("71d620fc773a11e288cce006e61619ba", $data);

//Note: A successful response is of binary type, where as a failed response
//      will be an associative array containing error message and status code. 

If the function call is successful the response is in binary format which can be saved as a PDF using File class.

The data supplied to populate the template is a hash containing field names and values. Field name refers to the placeholder(text, image, chart, table) which can be set in the editor. Valid values of each field type are as follows:

Text: Any valid string.
Image: Url of any image with public access.
Table: A matrix of string values supplied as a nested array.
Chart: There are three categories of charts that are currently available. Each chart type requires a different format for values:
Multi-value series chart(bar, stacked, line, area): A matrix of positive integer values supplied as nested array.

array (
  "chart_multi_value_field" => array(
    array("First", "Second", "Third"),
    array(20, 40, 30),
    array(50, 60, 10)
  )
)

Singe-value series chart(pie, doughnut): An array of positive integer values.

array ("chart_single_value_field" => array(20, 30, 40))

XY chart(point): A matrix of associative arrays supplied as nested array. Each hash is a pair of x, y values

array (
  "chart_xy_field" => array(
    array(
      array("x" => 20, "y" => 40),
      array("x" => 10, "y" => 30),
      array("x" => 70, "y" => 50)
    ),
    array(
      array("x" => 10, "y" => 30),
      array("x" => 20, "y" => 30),
      array("x" => 80, "y" => 30)
    )
  )
)

That's all.

Please mail at support@pagify.io if you need any further help. We always love hearing from our customers.

You can’t perform that action at this time.