#!/usr/bin/env node /** * Test script for the fixed PDF generation * Demonstrates the fixes for page breaks, A4 size, and page numbers */ const axios = require('axios'); // Test HTML content with 3 pages const testHTML = ` Property Brochure Test

Property Brochure - Page 1

Property Overview

This is the first page of our property brochure. It contains the main property information and overview.

Property Image 1

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.

Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.

Property Brochure - Page 2

Property Features

This is the second page showcasing the property features and amenities.

Property Image 2

Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.

Property Brochure - Page 3

Contact Information

This is the final page with contact information and call-to-action.

Property Image 3

Contact Details

Phone: (555) 123-4567

Email: info@property.com

Address: 123 Property Street, City, State 12345

Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

`; async function testFixedPDFGeneration() { try { console.log('๐Ÿงช Testing Fixed PDF Generation...'); console.log('๐Ÿ“„ Test HTML has 3 pages'); // Test the fixed PDF generation endpoint const response = await axios.post('http://localhost:8001/generate-fixed-pdf', { input: testHTML, output: 'test_property_brochure', return_download_link: true }, { headers: { 'Content-Type': 'application/json' }, timeout: 60000 // 60 second timeout }); if (response.data.success) { console.log('โœ… Fixed PDF Generation Test PASSED!'); console.log('๐Ÿ“Š Results:'); console.log(` - Success: ${response.data.success}`); console.log(` - Message: ${response.data.message}`); console.log(` - Download URL: ${response.data.download_url}`); console.log(` - File Size: ${response.data.file_size_mb} MB`); console.log(` - Fixes Applied: ${response.data.fixes_applied.join(', ')}`); console.log(''); console.log('๐ŸŽฏ Expected Results:'); console.log(' - PDF should have exactly 3 pages (no extra blank pages)'); console.log(' - A4 page size (210mm x 297mm)'); console.log(' - Proper page breaks between content'); console.log(' - Page numbers in footer: "Page X of 3"'); console.log(''); console.log('๐Ÿ”— Download the PDF to verify:'); console.log(` ${response.data.download_url}`); } else { console.log('โŒ Fixed PDF Generation Test FAILED!'); console.log('Response:', response.data); } } catch (error) { console.error('โŒ Test Error:', error.message); if (error.response) { console.error('Response data:', error.response.data); } } } async function testOriginalPDFGeneration() { try { console.log('๐Ÿงช Testing Original PDF Generation (for comparison)...'); // Test the original PDF generation endpoint const response = await axios.post('http://localhost:8000/generate-pdf', { input: testHTML, output: 'test_property_brochure_original', return_download_link: true }, { headers: { 'Content-Type': 'application/json' }, timeout: 60000 // 60 second timeout }); if (response.data.success) { console.log('๐Ÿ“Š Original PDF Results:'); console.log(` - Download URL: ${response.data.download_url}`); console.log(` - File Size: ${response.data.file_size_mb} MB`); console.log(''); console.log('โš ๏ธ Original PDF may have issues:'); console.log(' - Extra blank pages'); console.log(' - Incorrect page breaks'); console.log(' - Missing or incorrect page numbers'); } } catch (error) { console.error('โŒ Original Test Error:', error.message); } } // Run tests async function runTests() { console.log('๐Ÿš€ Starting PDF Generation Tests...'); console.log('====================================='); // Test original first await testOriginalPDFGeneration(); console.log(''); console.log('====================================='); // Test fixed version await testFixedPDFGeneration(); console.log(''); console.log('๐Ÿ Tests completed!'); console.log('Compare the two PDFs to see the improvements.'); } // Check if servers are running async function checkServers() { try { // Check original server await axios.get('http://localhost:8000/health', { timeout: 5000 }); console.log('โœ… Original PDF server is running on port 8000'); } catch (error) { console.log('โŒ Original PDF server is not running on port 8000'); console.log(' Start it with: node index.js'); } try { // Check fixed server await axios.get('http://localhost:8001/health', { timeout: 5000 }); console.log('โœ… Fixed PDF server is running on port 8001'); } catch (error) { console.log('โŒ Fixed PDF server is not running on port 8001'); console.log(' Start it with: node fixed-pdf-generation.js'); } } // Main execution async function main() { console.log('๐Ÿ” Checking servers...'); await checkServers(); console.log(''); await runTests(); } if (require.main === module) { main().catch(console.error); } module.exports = { testFixedPDFGeneration, testOriginalPDFGeneration };