1. Go to this page and download the library: Download pdfsquid/client-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
pdfsquid / client-php example snippets
try {
// initialize the library
// pass your credentials, $zone_name is zone associated with api access eg. 'eu1'
$client = new \PDFsquid\ZoneApi($api_key, $api_secret, $zone_name);
// convert synchronously
$file = $client->url2pdf('https://google.com');
// $file = $client->html2pdf('<b>Hello!</b>');
// download file as attachment, you can pass file name as option (default is conversionId value)
$file->downloadAsAttachment();
// you can also download file to show directly in browser
// $file->downloadInline();
// see more methods on file in class ResponseFile
}
catch(\PDFsquid\Exceptions\PDFsquidException $e) {
// Jump here on conversion error, authentication error or API is not available
// get HTTP code
$code = $e->getHttpCode();
// get errors
$errors = $e->getErrors();
/*
* $errors can be null or array e.g.:
* ["field"]=>
* string(9) "x-api-key"
* ["message"]=>
* string(18) "value is not valid"
* ["value"]=>
* string(35) "value passed to API"
*/
}
try {
// initialize the library
// pass your credentials, $zone_name is zone associated with api access eg. 'eu1'
$client = new \PDFsquid\ZoneApi($api_key, $api_secret, $zone_name);
// convert asynchronously
$result = $client->url2pdfAsync('https://google.com');
// $result = $client->html2pdf('<b>Hello!</b>', false);
// now $result is object with conversionId
// PDFsquid will call Client's handler defined in Client Panel when conversion ends (ping)
$conversionId = $result->conversionId;
}
catch(\PDFsquid\Exceptions\PDFsquidException $e) {
// Jump here on conversion error, authentication error or API is not available
// get HTTP code
$code = $e->getHttpCode();
// get errors
$errors = $e->getErrors();
/*
* $errors can be null or array e.g.:
* ["field"]=>
* string(9) "x-api-key"
* ["message"]=>
* string(18) "value is not valid"
* ["value"]=>
* string(35) "value passed to API"
*/
}
try {
$conversionId = $_GET['conversionId'];
// initialize the library
// pass your credentials, $zone_name is zone associated with api access eg. 'eu1'
$client = new \PDFsquid\ZoneApi($api_key, $api_secret, $zone_name);
// convert asynchronously
$file = $client->getFile($conversionId);
// save file on server
$file->saveFile('/var/www/files/', 'custom_file_name');
// see more methods on file in class ResponseFile
}
catch(\PDFsquid\Exceptions\PDFsquidException $e) {
// Jump here on conversion error, authentication error or API is not available
// get HTTP code
$code = $e->getHttpCode();
// get errors
$errors = $e->getErrors();
/*
* $errors can be null or array e.g.:
* ["field"]=>
* string(9) "x-api-key"
* ["message"]=>
* string(18) "value is not valid"
* ["value"]=>
* string(35) "value passed to API"
*/
}
bash
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.