We have created a PHP library that can handle the full functionality of our API. It's a class that lets you use all the options and functionality easily and has built in exception handling.
After you download the PHP library you can use our API in PHP as in the following example:
require 'pdfmyurl.php'; // include the class $pdf = new PDFmyURL ('yourlicensekey'); // initialize the class with your license // Now set some options, for example: $pdf->SetPageSize('A4'); // Set page format to A4 $pdf->SetPageOrientation('Portrait'); // Set page orientation to 'Portrait' $pdf->CreateFromURL ('www.google.com'); // Convert the Google Homepage to PDF $pdf->Display(); // Display the PDF for download to the user
Below is a list of functions that you can use, as well as all the exceptions that you may encounter when you're using the library. This will help you quickly take full advantage of our webpage / HTML to PDF API.
You will use the functions of the library in the following sequence:
Below is a list of all functions that you can use to set options for the conversion, the page layout and dimensions, margins, headers and footers, watermarking and much more.
The following functions allow you to customize the page dimensions and margins of your PDFs.
Function | Parameters | Description |
---|---|---|
SetPageSize | $pagesize | set the page size to one of the standard page formats like A4, B0, Letter etc |
SetPageOrientation | $orientation | set the orientation to either portrait or landscape |
SetPageDimensions | $width, $height | set the page size to exact dimensions or force a single page PDF |
SetDimensionUnit | $unit | set the unit of measure for custom dimensions to mm, in or pt |
SetMargins | $top,bottom,$left,$right | set the margins |
SetViewport | $width, $height | set the viewport, which by default is 1024 by 768 |
Below are some examples that show how to use these functions.
require 'pdfmyurl.php'; // include the class $pdf = new PDFmyURL ('yourlicensekey'); // initialize the class with your license $pdf->SetPageSize('A4'); // Set page format to A4 $pdf->SetPageOrientation('Portrait'); // Set page orientation to 'Portrait' $pdf->SetDimensionUnit('mm'); // Set unit of measurement to millimeter $pdf->SetPageDimensions(100, 200); // Set the page to be 100mm wide and 200mm high $pdf->SetPageDimensions(300, 0); // Set the page to be 300mm wide and force a single long page $pdf->SetMargins(10,10,5,5); // Set the top & bottom margin to 10mm and the left & right margin to 5mm $pdf->SetViewport(800,600); // Use a viewport of 800*600 for rendering