You can generate a PDF from a PHP application with DocRaptor by installing its Composer library, authenticating with an API key on your server, and sending either HTML content or a document URL. Test requests produce watermarked PDFs; switch to production mode only after checking the output. The integration steps below are documented by DocRaptor, but India-specific pricing, taxes, payment methods, account availability, and data-residency terms are not established by the cited pages.
Install the DocRaptor PHP library
Use Composer to add the official PHP agent, then load Composer’s autoloader in the PHP script that creates the document. DocRaptor’s PHP guide documents this package and client setup: DocRaptor PHP documentation.
As an Amazon Associate I earn from qualifying purchases.
composer require docraptor/docraptor
Run this from the application directory. The command adds the package to the project’s Composer dependencies; include vendor/autoload.php at runtime so PHP can load the DocRaptor classes.
Create and save a test PDF
Keep the API key in server-side configuration, such as an environment variable or secret manager, rather than putting it in browser JavaScript or committing it to source control. Configure the DocRaptor client with getConfig()->setUsername(...). For a REST request made directly instead of through the PHP library, DocRaptor documents HTTP Basic authentication with the API key as the username and an empty password.
#1 Best Overall
This complete PHP example submits inline HTML in test mode and writes the returned PDF bytes to output.pdf. Replace the environment-variable lookup with your secure configuration mechanism if needed.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$apiKey = getenv('DOCRAPTOR_API_KEY');
if (!$apiKey) {
throw new RuntimeException('Set DOCRAPTOR_API_KEY in the server environment.');
}
$docraptor = new DocRaptorDocApi();
$docraptor->getConfig()->setUsername($apiKey);
$doc = new DocRaptorDoc();
$doc->setTest(true); // Test PDFs have a watermark.
$doc->setDocumentType('pdf');
$doc->setDocumentContent('<html><body><h1>Hello from PHP</h1></body></html>');
try {
$pdf = $docraptor->createDoc($doc);
file_put_contents(__DIR__ . '/output.pdf', $pdf);
} catch (DocRaptorApiException $e) {
// Log diagnostic details securely; do not expose secrets or sensitive details to users.
error_log('DocRaptor request failed: ' . $e->getMessage());
throw $e;
}
In the synchronous PHP flow, createDoc($doc) returns binary PDF data on success. Save those bytes to a file, stream them to a user, or pass them to another server-side process. Test mode is intended for validation and adds a watermark; use an account key and turn off test mode for unwatermarked production documents after reviewing the rendered result. See DocRaptor’s broader conversion documentation.
Rank #2
Choose inline HTML or a document URL
Use document_content when the HTML is already available to your PHP application, such as a generated invoice or report. Use document_url when the document can be fetched from a URL that DocRaptor can access. The REST document-creation endpoint is https://api.docraptor.com/docs; its minimum PDF request identifies the type as pdf and supplies either content or a URL. Authentication, response behavior, and request construction are covered in the API overview.
For direct REST use, a typical JSON payload has this shape (send it with HTTP Basic authentication using the key as username and a blank password):
{
"type": "pdf",
"document_content": "<html><body>Report</body></html>",
"test": true
}
The API reference lists PDF, XLS, and XLSX output types; this guide focuses on PDF. Consult the API reference for the current schema and available options.
Configure rendering and JavaScript
DocRaptor uses Prince to render HTML to PDF. Page layout is primarily controlled by the HTML and CSS you submit; the PHP guide also demonstrates options such as media selection and a base URL for resolving relative resources. If your HTML references relative stylesheets, images, or fonts, provide an appropriate base URL or use accessible absolute URLs.
Rank #4
JavaScript is disabled by default. Enable it only when the page needs client-side rendering, for example to populate content before printing. Rendering completion can be difficult to determine for charts or externally fetched data; DocRaptor describes delayed-rendering controls and JavaScript configuration in its HTML and JavaScript guide.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Use asynchronous generation for long documents
According to DocRaptor’s PHP guide, synchronous generation has a 60-second maximum, while asynchronous generation has a 10-minute limit. The guide recommends asynchronous requests for large documents or documents that load many external assets. The PHP agent provides createAsyncDoc; use status polling or a callback to learn when the result is ready, then retrieve it according to the documented flow. Because these limits and API details can change, check the live PHP instructions before relying on them in production.
Deliver the result as bytes, a hosted URL, or an async job
A standard synchronous, non-hosted request returns PDF bytes for your application to save or deliver. Hosted-document delivery returns a public URL, while asynchronous creation returns a status identifier that you use to check progress and obtain the result. Hosted delivery details and plan-dependent terms are described on DocRaptor’s document hosting page; confirm current account and plan requirements there.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.What developers in India should verify
The cited DocRaptor PHP and API pages show how a PHP application can call the service, but they do not establish India-specific account eligibility, INR pricing, local payment options, GST or other tax treatment, data residency, or regulatory suitability. Do not infer these terms from a dollar-denominated price or from the fact that the API is technically reachable. If any of these affect procurement or compliance, confirm them directly with DocRaptor and your organization’s finance, legal, or security team before adopting the service.
Troubleshoot common integration problems
- Autoload or class-not-found error: confirm Composer completed successfully in the project directory and the script includes the matching
vendor/autoload.php. - Authentication failure: check that the server process receives the correct API key and that it is passed to
setUsername(). For direct REST calls, use Basic authentication with the key as username and an empty password. - Watermark on output: the request is in test mode. That is expected during validation; use production mode with an account key when an unwatermarked PDF is required.
- Missing images, styles, or fonts: verify the resources are accessible to the renderer and that relative paths resolve from the document URL or configured base URL.
- JavaScript-generated content is absent: JavaScript is off by default. Enable it only when required and use the documented rendering-delay controls where asynchronous page content needs time.
- Request times out on a large document: the synchronous flow is subject to the documented 60-second maximum. For large documents or many external assets, use asynchronous generation and poll or receive a callback.
- PDF cannot be opened after saving: preserve the binary response as-is rather than treating it as UTF-8 text, and verify that the write destination is writable and the complete response was saved.
Or skip the browser setup
If your need is a screenshot of a web page rather than a paginated PDF, ScreenshotNeo is a website screenshot API and MCP server for developers. Its one-call API returns an image; it is not a DocRaptor substitute for HTML-to-PDF generation. API details are in the ScreenshotNeo documentation.
Recommended Free Tools
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
ScreenshotNeo accepts cookie or consent banners like a visitor and removes 60+ known consent platforms, newsletter popups, and chat widgets before the capture; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, with the page verdict and billing status stated in response headers. Its MCP server provides screenshot, page-info, and PDF-capture tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.
Frequently Asked Questions
Can I use DocRaptor from India?
The documented API workflow is usable from a PHP application, but the cited pages do not establish India-specific account availability or commercial and data-residency terms. Confirm those points directly with DocRaptor if they matter to your use case.
Does the test PDF have a watermark?
Yes. Requests made with test mode enabled produce watermarked output.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Free tools Windows power users keep installed
One-click scans. No signup required.




