Simple FastAPI service that converts PDFs to PNG images. Designed to be used with n8n workflows.
-
Push to GitHub:
cd /path/to/helperpdf git init git add . git commit -m "Initial commit" git remote add origin https://github.com/kimbo128/helperpdf.git git push -u origin main
-
Deploy on Railway:
- Go to Railway
- Click "New Project" → "Deploy from GitHub repo"
- Select
kimbo128/helperpdf - Railway will auto-detect the Dockerfile and deploy!
-
Get your URL:
- After deployment, Railway gives you a URL like:
https://your-app.railway.app
- After deployment, Railway gives you a URL like:
GET /Returns service status and available endpoints.
POST /convert-pdf
Content-Type: application/json
{
"pdf_url": "https://example.com/document.pdf",
"dpi": 200
}Response:
{
"success": true,
"total_pages": 5,
"images": [
{
"page_number": 1,
"image_base64": "iVBORw0KGgoAAAANSUhEUgAA...",
"mime_type": "image/png",
"size_bytes": 245678
},
...
],
"message": "Successfully converted 5 pages to images"
}-
Add HTTP Request node
-
Configure:
- Method: POST
- URL:
https://your-app.railway.app/convert-pdf - Body:
{ "pdf_url": "{{ $json.pdf_url }}", "dpi": 200 }
-
Add Code node to process response:
// Convert base64 images to n8n binary format const images = $input.item.json.images; return images.map((img, index) => ({ json: { pageNumber: img.page_number, totalPages: $input.item.json.total_pages }, binary: { data: { data: Buffer.from(img.image_base64, 'base64'), mimeType: 'image/png', fileName: `page_${img.page_number}.png` } } }));
Replace your Python Code node with HTTP Request to this service!
Before (Python in n8n):
from pdf2image import convert_from_bytes
# ... complex code ...After (HTTP Request):
POST https://your-app.railway.app/convert-pdf
{
"pdf_url": "{{ $json.link }}?pdf=3103",
"dpi": 200
}
Manual Trigger
↓
Set PDF URL
↓
HTTP Request → POST /convert-pdf
↓
Code → Convert base64 to binary
↓
LinkedIn Upload
100-150: Low quality, small files (good for previews)200: Default, balanced quality/size300+: High quality, large files (print quality)
{
"pdf_url": "https://arturmarkus.com/post?pdf=3103",
"dpi": 200
}- Check if PDF URL is publicly accessible
- Verify URL returns actual PDF (not HTML page)
- Reduce
dpiparameter (try 150 or 100)
- Large PDFs may take time
- Increase n8n HTTP Request timeout to 60s+
# Install dependencies
pip install -r requirements.txt
# Run locally
python main.py
# Test endpoint
curl -X POST http://localhost:8000/convert-pdf \
-H "Content-Type: application/json" \
-d '{"pdf_url": "https://example.com/test.pdf"}'- No authentication required (add if needed for production)
- CORS enabled for all origins (customize as needed)
- Rate limiting not implemented (add nginx/Railway proxy if needed)
- FastAPI: Modern Python web framework
- pdf2image: PDF to image conversion
- Pillow: Image processing
- poppler-utils: PDF rendering engine
Your n8n workflows can now convert PDFs to images without local Python dependencies!