Endpoint: POST /api/convert
Full URL: https://pdf2image.truworth.app/api/convert
Request Body:
{
"pdfUrl": "https://example.com/document.pdf"
}
Response:
{
"success": true,
"images": {
"page1": "https://pdf2image.truworth.app/images/pdf-id/page-1.png",
"page2": "https://pdf2image.truworth.app/images/pdf-id/page-2.png"
},
"metadata": {
"page1": { "width": 595, "height": 842 },
"page2": { "width": 595, "height": 842 }
},
"pageCount": 2,
"convertedCount": 2,
"message": "Successfully converted 2 of 2 pages"
}
Using cURL from the command line:
curl -X POST 'https://pdf2image.truworth.app/api/convert' \
-H 'Content-Type: application/json' \
-d '{
"pdfUrl": "https://example.com/document.pdf"
}'
Using fetch in JavaScript:
// Using fetch API
fetch('https://pdf2image.truworth.app/api/convert', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
pdfUrl: 'https://example.com/document.pdf'
})
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
// data.images contains the converted image URLs
})
.catch(error => {
console.error('Error:', error);
});
Using requests in Python:
import requests
import json
url = "https://pdf2image.truworth.app/api/convert"
payload = {
"pdfUrl": "https://example.com/document.pdf"
}
headers = {
"Content-Type": "application/json"
}
response = requests.post(url, data=json.dumps(payload), headers=headers)
data = response.json()
if data.get("success"):
# Access the converted images
images = data.get("images")
for page, image_url in images.items():
print(f"{page}: {image_url}")
else:
print(f"Error: {data.get('error')}")
Endpoint: GET /api/test
Full URL: https://pdf2image.truworth.app/api/test
Use this endpoint to verify the API is functioning properly.
Response:
{
"success": true,
"message": "API is working",
"timestamp": "2024-04-09T12:34:56.789Z"
}