PHP library for the Box View API.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Box View PHP SDK

NOTE: No longer supported. Check out the official Box View PHP SDK.

Created by Daniel Pepin @ CommonPlaces, Inc
Sponsored by LawJacked


For general API documentaion, please review the Box View API Documentation.

To get started, Include the required classes:

require 'lib/box-view-api.php';
require 'lib/box-view-document.php';

Intializing the API class:

$api_key = 'YOUR_API_KEY';
$box = new Box_View_API($api_key);

Creating a document to upload:

$doc = new Box_View_Document();
$doc->name = 'My Awesome Document';
$doc->file_url = 'http://my-public-url';
$doc->thumbnails = '128×128,256×256'; // Comma-separated list of thumbnail dimensions of the format {width}x{height} e.g. 128×128,256×256
$doc->non_svg = false; // boolean (default=false)

Uploading a document to the API:


You can also upload local files through the API:

$doc = new Box_View_Document(array(
  'name' => 'My Local File',
  'file_path' => '/path/to/file/CV_Template1.doc',

Uploading an array of documents to the API:

// Create array of Box_View_Document objects.
$docs[] = new Box_View_Document(array('file_url' => ''));
$docs[] = new Box_View_Document(array('file_url' => ''));
$docs[] = new Box_View_Document(array('file_url' => ''));

// Wrap API calls in try/catch.
catch(Exception $e)
  log('error', $e->getMessage());

After some time, the document will be processed and can be viewed:

echo $doc->session->url; // Links to the HTML5 document.

Embed the document in an iframe.

<iframe src="<?= $doc->session->url ?>"></iframe>

Retrieve a thumbnail image of the first page of a document. Thumbnails can have a width between 16 and 1024 pixels and a height between 16 and 768 pixels.

$img = $box->getThumbnail($doc, $width, $height);
<img src="data:image/png;base64,<?= base64_encode($img) ?>"/>

Showing a PDF version of the file.

header('Content-Type: application/pdf');
print $doc->content->pdf;

Getting a Zip folder containing the HTML5 files for the document:

file_put_contents($doc->name . '.zip', $doc->content->zip);
// Unzip the file.

Deleting the document:


####Handling Exceptions API calls will throw an instance of Box_View_Exception when an error is encountered.
You should wrap your API calls with a try/catch.

catch(Exception $e)
  log('error', $e->getMessage(), $http_code = $e->getCode());