Skip to content

About

yes

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

20 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

WebP to PDF API

A lightweight Python service that retrieves image-based gallery pages and packages them into a downloadable PDF.

Built with Flask, Requests, Pillow, and fpdf2. Designed for serverless deployment on Vercel.

Features

  • Generate a PDF from a gallery ID in a single request.
  • Preserve each page's aspect ratio.
  • Return the PDF directly without temporary file hosting.
  • Support optional upstream API authentication.
  • Validate image sources and enforce download limits.
  • Return structured JSON errors when an upstream request fails.

API

Convert a gallery

GET /api/nh_to_pdf?id=123456

Returns a PDF attachment with the gallery ID and title in the filename.

Health check

GET /

Returns a small JSON response indicating that the service is running.

Deployment

The project uses Vercel's Python runtime.

  1. Import this repository into Vercel.
  2. Keep the project root as the deployment root.
  3. Deploy using the included vercel.json configuration.
  4. Add optional environment variables if your upstream API account requires authentication.

Configuration

Variable Required Description
NHENTAI_API_KEY No Optional API key for authenticated upstream requests.
NHENTAI_USER_AGENT No Custom User-Agent used for upstream API and image requests.

Configure variables in Vercel → Project Settings → Environment Variables, then redeploy. Keep credentials out of source control.

Resource limits

To keep serverless execution predictable, each conversion is subject to these limits:

  • Gallery IDs must be numeric.
  • Maximum of 300 pages per gallery.
  • Maximum of 20 MB per image.
  • Maximum of 180 MB total source-image data.
  • Maximum of 60 megapixels per image.
  • Bounded network request timeouts.

The service rejects unsupported or corrupt images and reports upstream API or CDN failures as JSON responses.

Local development

Requires Python 3.10 or newer.

python -m pip install -r requirements.txt
python server.py

The development server listens on port 3000 by default. Set the PORT environment variable to use another port.

Implementation

Gallery metadata is retrieved through the upstream v2 API. Page images are fetched from the provider's image CDN and converted to PDF in memory with fpdf2.

The archive download endpoint offered by the upstream provider is not used because this service returns PDF output. The PDF is generated during the request and is not stored between invocations.

Availability depends on the upstream API and image CDN, including their rate limits and hosting-provider access policies.

About

yes

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages