This page serves as a guide for using the Pdfcrowd API to capture web pages and HTML content to image screenshots in PHP applications. The API is designed for easy use and straightforward integration. For general information about the converter, refer to the HTML to Image API documentation.
Check out other installation options such as Composer or GitHub.
Below are PHP examples to help you quickly get started with the API. Explore our additional examples for more insights.
To access the API, you will need to use your Pdfcrowd username and API key. For initial testing, you may use the following demo credentials without registering:
demo
ce544b6ea52a5621fb9d55f8b542d14d
To obtain your personal API credentials, consider starting a free API trial or purchasing the API license.
Quickly preview the API output by entering a URL or uploading an HTML file below. This will generate previews with different API settings. You can then choose the one you prefer and copy the respective API integration code into your PHP application.
The API supports converting a webpage, an HTML file, or a string containing HTML into various output forms such as local files, stream objects, or variables. For detailed information about conversion inputs, please refer to the Conversion Input section of our documentation.
The table below highlights the most common customizations you might find useful. Refer to the Option Reference for a detailed description of all available options. For an interactive experience, explore these options in the API Playground.
For additional customization options and troubleshooting, please visit the FAQ section of our website where you can find answers and help related to frequent queries and common issues.
Image size | Customize the dimensions of the captured images using the setScreenshotWidth() and setScreenshotHeight(). |
Image format | Change the ouput image format using setOutputFormat(). |
Hide or Remove Contents |
Utilize the following classes in your HTML code to hide or remove
elements from the output:
|
Custom CSS Styling |
To customize CSS styling specifically for the conversion, use
setCustomCss() to inject additional styles.
Alternatively, you can directly incorporate conversion-specific styling into your main stylesheet. Just prefix your CSS selectors with `.pdfcrowd-body` to ensure
the styles apply only during the conversion process. For
example:.pdfcrowd-body h1 { font-size: 48px; } .pdfcrowd-body footer { display: none; }
|
Use `@media print` |
Activate the print version of a webpage (if
available) using setUsePrintMedia().
This function instructs the API
to apply the CSS rules defined within the `@media print`
stylesheet, ensuring the output mirrors the print-optimized version of the webpage.
|
Inject Custom JavaScript | Utilize setCustomJavascript() or setOnLoadJavascript() to modify HTML content using custom JavaScript scripts. These scripts run when the page loads, allowing you to dynamically alter elements, styles, or behavior. In addition to the standard browser JavaScript APIs, your scripts can leverage helper functions provided by our JavaScript library. |
HTML Templates | Add data to your HTML templates for dynamic generation tailored to specific content needs. For details, refer to HTML Template to Image. |
It is recommended that you implement error handling to catch errors the API may return. Effective error handling is vital as it ensures application stability and provides clearer diagnostics. See the example code below for guidance on implementing error handling, and refer to this list of status codes for more information.
try { // call the API } catch(\Pdfcrowd\Error $why) { // print the error error_log("Pdfcrowd Error: {$why}\n"); // print the error code error_log("Pdfcrowd Error Code: {$why->getCode()}\n"); // print the error message error_log("Pdfcrowd Error Message: {$why->getMessage()}\n"); }
Refer to the HTML to Image PHP Reference for a description of all API methods.