pub async fn pdf_from_url(
pool: &State<SharedPool>,
query: PdfFromUrlQuery,
) -> HandlerResult<PdfResponder>Expand description
Generate PDF from a URL.
This handler converts a web page to PDF using the browser pool.
§Endpoint
GET /pdf?url=https://example.com&filename=output.pdf§Query Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
url | string | Yes | - | URL to convert (must be valid HTTP/HTTPS) |
filename | string | No | "document.pdf" | Output filename |
waitsecs | u64 | No | 5 | Seconds to wait for JavaScript |
landscape | bool | No | false | Use landscape orientation |
download | bool | No | false | Force download vs inline display |
print_background | bool | No | true | Include background graphics |
§Response
§Success (200 OK)
Returns PDF binary data with headers:
Content-Type: application/pdfContent-Disposition: inline; filename="document.pdf"(orattachmentifdownload=true)Cache-Control: no-cache
§Errors
| Status | Code | Description |
|---|---|---|
| 400 | INVALID_URL | URL is empty or malformed |
| 502 | NAVIGATION_FAILED | Failed to load the URL |
| 503 | BROWSER_UNAVAILABLE | No browsers available in pool |
| 504 | TIMEOUT | Operation timed out |
§Examples
§Basic Request
GET /pdf?url=https://example.com§With Options
GET /pdf?url=https://example.com/report&filename=report.pdf&landscape=true&waitsecs=10§Force Download
GET /pdf?url=https://example.com&download=true&filename=download.pdf§Usage in App
ⓘ
rocket::build()
.manage(pool)
.mount("/", routes![pdf_from_url])