To convert an existing page URL to PDF from a Laravel application, call DocRaptor’s PHP client from server-side code: install docraptor/docraptor, keep your API key in server configuration, set the document type to pdf, pass the URL with setDocumentUrl(), then return the binary result as a download or save it to storage. DocRaptor must be able to retrieve the URL; if Laravel already has the HTML, you can instead send it as document content.
Install and configure DocRaptor in Laravel
DocRaptor’s official PHP client is a Composer package. Run this from your Laravel project directory:
As an Amazon Associate I earn from qualifying purchases.
composer require docraptor/docraptor
Store the API key in the server-side environment, not in browser JavaScript or a publicly accessible page. For example, add this to .env:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
DOCRAPTOR_API_KEY=your_api_key
Then expose it through Laravel configuration, for example in config/services.php:
#1 Best Overall
'docraptor' => [
'key' => env('DOCRAPTOR_API_KEY'),
],
This is standard Laravel configuration guidance; DocRaptor’s PHP documentation does not provide a Laravel-specific service provider or facade. Its documented PHP client uses the API key as the HTTP Basic Authentication username, with an empty password. See DocRaptor’s PHP documentation and API documentation.
Convert a URL and return a PDF download
The following controller action is an illustrative Laravel-side integration using the documented PHP client. Replace the example URL with a URL that DocRaptor can retrieve. The value returned by createDoc() is binary PDF data, not a path or a JSON object.
<?php
namespace AppHttpControllers;
use DocRaptorApiException;
use DocRaptorDoc;
use DocRaptorDocApi;
use IlluminateHttpRequest;
use IlluminateSupportFacadesLog;
class PdfController extends Controller
{
public function download(Request $request)
{
$url = 'https://example.com/report';
$api = new DocApi();
$api->getConfig()->setUsername(config('services.docraptor.key'));
$doc = new Doc();
$doc->setTest(true); // Test PDFs are watermarked.
$doc->setDocumentType('pdf');
$doc->setDocumentUrl($url);
try {
$pdf = $api->createDoc($doc);
} catch (ApiException $e) {
Log::error('DocRaptor PDF generation failed', [
'code' => $e->getCode(),
'message' => $e->getMessage(),
'response_body' => $e->getResponseBody(),
]);
abort(502, 'The PDF could not be generated.');
}
return response($pdf, 200, [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="report.pdf"',
]);
}
}
The catch block illustrates one way to keep details out of the user-facing response. Check the installed client version’s exception methods if its API differs; never log the API key or expose sensitive exception details to users. In production, set test mode to false according to your account configuration, because test output is watermarked.
Choose URL input or HTML content
| Input | Use it when | Important detail |
|---|---|---|
document_url |
You want DocRaptor to request an existing page. | The URL must be reachable by DocRaptor. A URL on localhost or behind application authentication is not automatically accessible; the reviewed documentation does not provide a Laravel private-route authentication recipe. |
document_content |
Your Laravel code already has the HTML or XML to render. | When HTML uses relative asset paths, provide a base URL or an HTML <base> element so images, stylesheets and other resources can resolve. |
The PHP client exposes URL input through setDocumentUrl($url). For direct HTML input, use the client’s document-content setting supported by its installed version. Do not assume sending HTML also makes private image or stylesheet URLs accessible: the renderer still needs to fetch referenced resources.
Choose rendering behavior for the source page
Print or screen CSS
DocRaptor uses print media by default. If the PDF layout is wrong because the page’s print styles hide or rearrange content, try the screen media option, prince_options[media], set to screen. Print is generally the appropriate starting point for a document; screen is useful when you want the page’s browser-like styling.
JavaScript and dynamic content
JavaScript is disabled by default. Enable it when the page needs scripts to populate content, and consider an explicit rendering delay for charts or externally loaded data. A delay can help allow content to appear, but it is not a guarantee that every asynchronous page will finish consistently.
Rank #3
Test mode
Use test=true while developing to exercise generation without producing a normal production PDF. Test documents are watermarked; switch to non-test mode for unwatermarked production output. DocRaptor’s API reference states that test documents do not count against monthly limits.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Scan for outdated or missing drivers - takes under a minute3Clear out junk files and repair common Windows errorsReturn the PDF or save it
Download from the request
The controller example returns the binary payload with Content-Type: application/pdf and an attachment filename. This response handling is Laravel implementation guidance based on the client’s documented binary response; it is not a DocRaptor-provided Laravel example.
Store the generated file
If the application should retain the PDF rather than immediately download it, write the binary string using Laravel’s storage disk:
Rank #4
use IlluminateSupportFacadesStorage;
$path = 'reports/report.pdf';
Storage::disk('local')->put($path, $pdf);
return response()->json(['path' => $path]);
Choose a private disk or an access-controlled destination for sensitive documents. The binary payload should be written as-is; do not convert it to text or JSON before storage.
Use asynchronous generation for longer jobs
A synchronous createDoc() call returns the binary document in the request flow. If generation time does not fit the web request’s needs, DocRaptor also supports asynchronous API usage: the request returns a status identifier, and callbacks can report successful completion. Generation errors do not call the callback, so the application still needs status and error handling rather than assuming a callback will always arrive. The sources establish the async and callback behavior but do not prescribe a particular Laravel queue or job design.
Free tools Windows power users keep installed
One-click scans. No signup required.
Common failures and fixes
- The URL cannot be fetched: Check that the URL is reachable from DocRaptor, not merely from the Laravel server or your own browser. Localhost and protected routes require an access approach not specified by the cited documentation.
- The response is not a PDF: Failed requests may return an XML error body. Inspect the HTTP status and client exception details; do not treat every response body as a valid PDF.
- The PDF has a watermark: The document was generated in test mode. Keep that mode for development and disable it for production output as appropriate to the account.
- Styles differ from the browser: Print media is the default. Try
prince_options[media]set toscreenif the browser-style layout is the intended result. - Charts or dynamic sections are missing: JavaScript is off by default. Enable it if needed and use an explicit delay where the page depends on scripts or external data.
- Images or stylesheets are missing in HTML-content mode: Resolve relative paths with a base URL or an HTML
<base>element, and confirm the referenced assets are reachable. - Generation fails in the application: Catch
DocRaptorApiException, inspect its message, code and response body in protected logs, and return a generic error to the end user. Keep credentials out of logs and responses.
Or skip the browser setup
If you only need a screenshot of a URL rather than a PDF, ScreenshotNeo is a website screenshot API and MCP server. Its one-call endpoint returns an image; it is not a replacement for DocRaptor when the required output is a PDF.
Best Value
For example, using cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation. It removes cookie banners, newsletter popups and chat widgets before capture; bot checks, blank pages and failed loads are never billed; and its MCP server lets AI agents take screenshots. The Free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for ScreenshotNeo’s free plan.
Frequently Asked Questions
Can DocRaptor convert a URL directly to PDF?
Yes. Set the document type to PDF and pass the page URL with the PHP client’s setDocumentUrl() method.
Does the PHP client return a file path?
No. A successful synchronous call returns binary PDF data, which your Laravel code can send in a download response or write to storage.
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.




