# ZERO-WHITESPACE PDF Generator API - Usage Examples ## Overview This API generates exact PDFs with zero whitespace and supports both A3 and A4 formats. ## Features - ✅ **Zero Whitespace**: Complete elimination of unwanted spacing - ✅ **Format Options**: A3 (297mm x 420mm) and A4 (210mm x 297mm) - ✅ **Exact Output**: PDFs match HTML exactly without extra pages - ✅ **Advanced HTML Processing**: Removes all unnecessary elements - ✅ **Download Links**: Get direct download URLs for generated PDFs ## API Endpoints ### 1. Generate PDF **POST** `/generate-pdf` #### Request Body (JSON) ```json { "input": "Your HTML content here", "output": "my-property-brochure", "format": "A4", "return_download_link": true } ``` #### Parameters - `input` (required): HTML content to convert to PDF - `output` (optional): Custom filename (without extension) - `format` (optional): "A3" or "A4" (default: "A4") - `return_download_link` (optional): true/false (default: false) #### Response (Download Link) ```json { "success": true, "message": "ZERO-WHITESPACE A4 PDF generated successfully", "download_url": "https://salesforce.tech4biz.io/download/property_brochure_A4_abc123.pdf", "filename": "property_brochure_A4_abc123.pdf", "format": "A4", "file_size_mb": "2.45", "expires_at": "2024-01-15T10:30:00.000Z", "generated_at": "2024-01-08T10:30:00.000Z", "pdf_id": "abc123", "status": "download_ready", "features": ["zero_whitespace", "exact_output", "minimal_margins"] } ``` ### 2. Health Check **GET** `/health` #### Response ```json { "status": "healthy", "timestamp": "2024-01-08T10:30:00.000Z", "version": "9.0.0-zero-whitespace-a3-a4", "supported_formats": ["A3", "A4"], "features": [ "zero_white_spaces", "zero_margins", "advanced_html_preprocessing", "complete_css_reset", "no_extra_pages", "a3_a4_formats", "exact_pdf_output", "download_links", "base64_response", "infinite_timeouts", "format_validation" ] } ``` ## Usage Examples ### Example 1: Generate A4 PDF with Download Link ```bash curl -X POST http://localhost:8000/generate-pdf \ -H "Content-Type: application/json" \ -d '{ "input": "

My Property

Beautiful home for sale

", "output": "property-brochure", "format": "A4", "return_download_link": true }' ``` ### Example 2: Generate A3 PDF with Download Link ```bash curl -X POST http://localhost:8000/generate-pdf \ -H "Content-Type: application/json" \ -d '{ "input": "

Large Property

Spacious home with garden

", "output": "large-property", "format": "A3", "return_download_link": true }' ``` ### Example 3: JavaScript/Node.js Usage ```javascript const axios = require('axios'); async function generatePDF(htmlContent, format = 'A4') { try { const response = await axios.post('http://localhost:8000/generate-pdf', { input: htmlContent, format: format, return_download_link: true }); if (response.data.success) { console.log('PDF Generated:', response.data.download_url); return response.data.download_url; } } catch (error) { console.error('Error:', error.response?.data?.error || error.message); } } // Usage const htmlContent = '

My Property

'; generatePDF(htmlContent, 'A4'); ``` ### Example 4: Python Usage ```python import requests import json def generate_pdf(html_content, format='A4'): url = 'http://localhost:8000/generate-pdf' data = { 'input': html_content, 'format': format, 'return_download_link': True } response = requests.post(url, json=data) if response.status_code == 200: result = response.json() if result['success']: print(f"PDF Generated: {result['download_url']}") return result['download_url'] else: print(f"Error: {response.json().get('error', 'Unknown error')}") # Usage html_content = '

My Property

' generate_pdf(html_content, 'A4') ``` ## Key Improvements ### 1. Zero Whitespace - Complete CSS reset eliminates all default browser spacing - Advanced HTML preprocessing removes unnecessary whitespace - Zero margins ensure exact PDF output ### 2. Format Support - **A4**: 210mm x 297mm (standard document size) - **A3**: 297mm x 420mm (larger format for detailed layouts) ### 3. Exact Output - PDFs match HTML exactly without extra pages - No unwanted spacing or margins - Perfect page count matching ### 4. Advanced Processing - Removes HTML comments and empty elements - Eliminates whitespace between tags - Optimizes content for PDF generation ## Testing Run the test script to verify functionality: ```bash node test-pdf-generation.js ``` This will test all preview templates with both A3 and A4 formats.