This is the documentation of the PHP client library for the legacy Pdfcrowd API v1. We strongly recommend the new improved Pdfcrowd API v2 for new integrations.
Install the Pdfcrowd API client library for PHP.
This code converts a web page and sends
the generated PDF as an HTTP response
(in the following examples, do not forget to replace "username"
and "apikey"
with your username and API key)
<?php require 'pdfcrowd.php'; try { // create an API client instance $client = new Pdfcrowd("your_username", "your_apikey"); // convert a web page and store the generated PDF into a $pdf variable $pdf = $client->convertURI('http://www.google.com/'); // set HTTP response headers header("Content-Type: application/pdf"); header("Cache-Control: max-age=0"); header("Accept-Ranges: none"); header("Content-Disposition: attachment; filename=\"google_com.pdf\""); // send the generated PDF echo $pdf; } catch(PdfcrowdException $why) { echo "Pdfcrowd Error: " . $why; } ?>
You can also convert raw HTML code, just use the convertHtml()
method instead of convertURI()
:
$pdf = $client->convertHtml("<head></head><body>My HTML Layout</body>");
The API lets you also convert a local HTML file:
$pdf = $client->convertFile("/path/to/MyLayout.html");
You can save the generated PDF to a file:
$out_file = fopen("document.pdf", "wb"); $client->convertHtml("<head></head><body>My HTML Layout</body>", $out_file); fclose($out_file);
try { // .. // call the API } catch(PdfcrowdException $why) { // $why->getMessage() returns an error message }
Provides access to the Pdfcrowd API from your PHP applications.
function __construct($username, $apikey)
function convertHtml($html, $outstream=null)
fopen()
.
If outstream is not provided then the return value is a string
containing the created PDF.
function convertFile($fpath, $outstream=null)
fopen()
.
If outstream is not provided then the return value is a string
containing the created PDF.
function convertURI($url, $outstream=null)
fopen()
.
If outstream is not provided then the return value is a string
containing the created PDF.
function setPageWidth($value)
function setPageHeight($value)
function setPageMargins($top, $right, $bottom, $left)
function setHorizontalMargin($value)
function setVerticalMargin($value)
function setFooterHtml($html)
function setFooterUrl($url)
function setHeaderHtml($html)
function setHeaderUrl($url)
function setHeaderFooterPageExcludeList($exclist)
function setPageNumberingOffset($offset)
function enableImages($value)
function enableBackgrounds($value)
function setHtmlZoom($value)
function enableJavaScript($value)
function enableHyperlinks($value)
function setDefaultTextEncoding($value)
utf-8
.
function usePrintMedia($value)
print
CSS media type
is used (if available).
function setEncrypted($value)
function setUserPassword($pwd)
function setOwnerPassword($pwd)
function setNoPrint($value)
function setNoModify($value)
function setNoCopy($value)
function setPageLayout($value)
SINGLE_PAGE
CONTINUOUS
CONTINUOUS_FACING
function setPageMode($value)
FULLSCREEN
- Full-screen mode.function setInitialPdfZoomType($value)
FIT_WIDTH
FIT_HEIGHT
FIT_PAGE
function setInitialPdfExactZoom($value)
function setPdfScalingFactor($value)
function setPageBackgroundColor($value)
function setTransparentBackground($value)
body {background-color:rgba(255,255,255,0.0);}
function setAuthor($author)
function setWatermark($url, $offset_x=0, $offset_y=0)
function setWatermarkRotation($angle)
function setWatermarkInBackground($value)
function useSSL($use_ssl)
function numTokens()
function setMaxPages($npages)
function setFailOnNon200($value)
Derived from Exception
. It is thrown when an error
occurs. Use getMessage()
method to get the error
message. getCode()
returns the HTTP status code.
Page dimensions and margins can be specified in inches (in), millimeters (mm),
centimeters (cm), or points (pt). If no units are specified, points are
assumed. Examples: "210mm"
, "8.5in"
.