PDF API¶
The PDF API provides endpoints for processing PDF files from URLs, extracting metadata, converting PDFs to different formats, and manipulating PDF documents.
Authentication¶
All PDF API endpoints require authentication using an API key. Include your API key in the X-API-KEY
header of your requests.
curl -X POST "https://magic-meal-kits-xxxxx.run.app/api/v1/pdfinfo" \
-H "X-API-KEY: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/document.pdf"
}'
Video¶
Endpoints¶
PDF Info¶
Get metadata information about a PDF file from a URL.
POST /api/v1/pdfinfo
¶
Request Body:
{
"url": "https://example.com/document.pdf",
"options": ["optional", "parameters"]
}
Field | Type | Required | Description |
---|---|---|---|
url | String | Yes | URL of the PDF file |
options | String[] | No | Additional pdfinfo command line options |
Example Request:
curl -X POST "https://magic-meal-kits-xxxxx.run.app/api/v1/pdfinfo" \
-H "X-API-KEY: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/document.pdf"
}'
Example Response:
{
"success": true,
"data": {
"title": "Document Title",
"author": "Document Author",
"creator": "Application Name",
"producer": "PDF Library",
"creationDate": "2023-01-15T12:34:56.000Z",
"modificationDate": "2023-02-20T10:11:12.000Z",
"tagged": "no",
"form": "none",
"pages": 5,
"encrypted": "no",
"pageSize": "612 x 792 pts (letter)",
"fileSize": "1024000 bytes",
"optimized": "no",
"pdfVersion": "1.7"
}
}
PDF to Text¶
Convert PDF file to plain text format.
POST /api/v1/pdftotext
¶
Request Body:
{
"url": "https://example.com/document.pdf",
"options": ["optional", "parameters"]
}
Field | Type | Required | Description |
---|---|---|---|
url | String | Yes | URL of the PDF file |
options | String[] | No | Additional pdftotext command line options |
Supported Options:
- -layout
: Maintain original physical layout
- -raw
: Keep strings in content stream order
- -enc encoding
: Output text encoding (UTF-8, ASCII, etc.)
- -eol unix/dos/mac
: End of line convention
- -f number
: First page to convert
- -l number
: Last page to convert
Example Request:
curl -X POST "https://magic-meal-kits-xxxxx.run.app/api/v1/pdftotext" \
-H "X-API-KEY: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/document.pdf",
"options": ["-layout", "-f", "1", "-l", "5"]
}'
Example Response:
{
"success": true,
"data": "Extracted text content from the PDF file...",
"pages": 5
}
PDF to HTML¶
Convert PDF to HTML format.
POST /api/v1/pdftohtml
¶
Request Body:
{
"url": "https://example.com/document.pdf",
"options": ["optional", "parameters"]
}
Field | Type | Required | Description |
---|---|---|---|
url | String | Yes | URL of the PDF file |
options | String[] | No | Additional pdftohtml command line options |
Example Request:
curl -X POST "https://magic-meal-kits-xxxxx.run.app/api/v1/pdftohtml" \
-H "X-API-KEY: your-api-key" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/document.pdf"
}'
Example Response:
{
"success": true,
"data": "<html><body>HTML content converted from the PDF...</body></html>"
}
Error Handling¶
If an error occurs during processing, the API returns an error response:
{
"success": false,
"error": "Error message description"
}
Common error codes:
- 400 Bad Request: Invalid parameters or request body
- 401 Unauthorized: Missing or invalid API key
- 404 Not Found: PDF file not found or URL is invalid
- 429 Too Many Requests: Rate limit exceeded
- 500 Internal Server Error: Server-side error