Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

kimbo128/helperpdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PDF to Images Helper for n8n

Simple FastAPI service that converts PDFs to PNG images. Designed to be used with n8n workflows.

🚀 Deploy to Railway

  1. 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
  2. Deploy on Railway:

    • Go to Railway
    • Click "New Project" → "Deploy from GitHub repo"
    • Select kimbo128/helperpdf
    • Railway will auto-detect the Dockerfile and deploy!
  3. Get your URL:

    • After deployment, Railway gives you a URL like: https://your-app.railway.app

📡 API Endpoints

Health Check

GET /

Returns service status and available endpoints.

Convert PDF to Images

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"
}

🔧 Use in n8n

Method 1: HTTP Request Node

  1. Add HTTP Request node

  2. Configure:

    • Method: POST
    • URL: https://your-app.railway.app/convert-pdf
    • Body:
      {
        "pdf_url": "{{ $json.pdf_url }}",
        "dpi": 200
      }
  3. 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`
        }
      }
    }));

Method 2: Direct in Workflow

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
}

🎯 Example n8n Workflow

Manual Trigger
    ↓
Set PDF URL
    ↓
HTTP Request → POST /convert-pdf
    ↓
Code → Convert base64 to binary
    ↓
LinkedIn Upload

⚙️ Configuration

DPI (Image Quality)

  • 100-150: Low quality, small files (good for previews)
  • 200: Default, balanced quality/size
  • 300+: High quality, large files (print quality)

Example:

{
  "pdf_url": "https://arturmarkus.com/post?pdf=3103",
  "dpi": 200
}

🐛 Troubleshooting

PDF Download Fails

  • Check if PDF URL is publicly accessible
  • Verify URL returns actual PDF (not HTML page)

Images Too Large

  • Reduce dpi parameter (try 150 or 100)

Timeout

  • Large PDFs may take time
  • Increase n8n HTTP Request timeout to 60s+

📝 Local Development

# 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"}'

🔐 Security Notes

  • 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)

📦 Tech Stack

  • FastAPI: Modern Python web framework
  • pdf2image: PDF to image conversion
  • Pillow: Image processing
  • poppler-utils: PDF rendering engine

🎉 That's it!

Your n8n workflows can now convert PDFs to images without local Python dependencies!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published