Skip to content

1funlab/x2pdf

Repository files navigation

x2pdf Service

A PDF generation service for Cloudflare Workers deployment.

🚀 Live Demo: https://x2pdf.1funlab.com/api/pdf

Features

  • Generate PDF resumes from JSON data
  • Serverless deployment on Cloudflare Workers
  • Complete PDF generation API with CORS support
  • High performance and global edge distribution
  • TypeScript implementation with full type safety

Quick Start

Local Development

npm install
npm run dev

This starts a local development server using Wrangler.

Production Deployment

npm run deploy

Deploy to Cloudflare Workers in production.

Development Deployment

npm run deploy:dev

Deploy to Cloudflare Workers development environment.

API Endpoints

  • GET / - Service information
  • GET /health - Health check
  • POST /api/pdf - Generate PDF (binary response)
  • POST /api/pdf/json - Generate PDF (JSON response with base64)

Example Usage

Live API Example

The service is deployed and available at: https://x2pdf.1funlab.com

Generate PDF (Binary)

curl -X POST https://x2pdf.1funlab.com/api/pdf \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "contact": {"email": "john@example.com", "phone": "123-456-7890"}}' \
  --output resume.pdf

Generate PDF (JSON)

curl -X POST https://x2pdf.1funlab.com/api/pdf/json \
  -H "Content-Type: application/json" \
  -d '{"name": "John Doe", "contact": {"email": "john@example.com", "phone": "123-456-7890"}}'

Postman Testing

You can test the API using Postman as shown in the screenshot below:

Postman Usage Example

The screenshot shows how to:

  1. Set the request method to POST
  2. Use the endpoint /api/pdf or /api/pdf/json
  3. Set Content-Type header to application/json
  4. Include resume data in the request body

Cloudflare Workers Deployment

The service is deployed on Cloudflare Workers with custom domain routing:

Cloudflare Workers Deployment

This screenshot shows the production deployment status in the Cloudflare Workers dashboard, including:

  • Deployment history and status
  • Custom domain configuration (x2pdf.1funlab.com)
  • Performance metrics and analytics
  • Worker version management

Project Structure

  • /src/worker.ts - Main Cloudflare Workers implementation (TypeScript)
  • /src/test-pdf-generation.ts - PDF generation test script
  • /src/test-api.ts - API testing script
  • /dist/ - Compiled JavaScript files
  • /wrangler.jsonc - Workers deployment configuration
  • /sample.json - Example JSON data for testing
  • /tsconfig.json - TypeScript configuration
  • /images/1.png - Postman usage example screenshot
  • /images/2.png - Cloudflare Workers deployment dashboard screenshot

Available Scripts

  • npm run dev - Local development with Wrangler (TypeScript hot reload)
  • npm run dev:local - Local development with local runtime
  • npm run build - Compile TypeScript to JavaScript
  • npm run build:worker - Build optimized worker bundle with esbuild
  • npm run test - Run PDF generation test
  • npm run test:api - Run API endpoint tests
  • npm run test:validate - Validate sample.json structure
  • npm run test:all - Run all tests
  • npm run deploy - Deploy to production
  • npm run deploy:dev - Deploy to development environment
  • npm run clean - Clean build artifacts

Technology Stack

  • Runtime: Cloudflare Workers
  • Language: TypeScript
  • PDF Generation: pdf-lib
  • Build Tool: esbuild + TypeScript compiler
  • Development: Wrangler CLI
  • Deployment: Cloudflare Workers Platform

Configuration

Configuration is managed through Cloudflare Workers dashboard or wrangler.toml. See wrangler.jsonc for deployment settings.

Learn More

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors