259 lines
8.6 KiB
JavaScript
259 lines
8.6 KiB
JavaScript
#!/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 = `
|
|
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Property Brochure Test</title>
|
|
<style>
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 20px;
|
|
line-height: 1.6;
|
|
}
|
|
.page {
|
|
min-height: 100vh;
|
|
page-break-after: always;
|
|
padding: 20px;
|
|
border: 1px solid #ddd;
|
|
margin-bottom: 20px;
|
|
}
|
|
.page:last-child {
|
|
page-break-after: avoid;
|
|
}
|
|
.header {
|
|
background: #007bff;
|
|
color: white;
|
|
padding: 20px;
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
.content {
|
|
padding: 20px;
|
|
}
|
|
.image-placeholder {
|
|
width: 100%;
|
|
height: 200px;
|
|
background: #f0f0f0;
|
|
border: 2px dashed #ccc;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
margin: 20px 0;
|
|
}
|
|
.footer {
|
|
margin-top: auto;
|
|
text-align: center;
|
|
padding: 20px;
|
|
background: #f8f9fa;
|
|
border-top: 1px solid #ddd;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<!-- Page 1 -->
|
|
<div class="page">
|
|
<div class="header">
|
|
<h1>Property Brochure - Page 1</h1>
|
|
</div>
|
|
<div class="content">
|
|
<h2>Property Overview</h2>
|
|
<p>This is the first page of our property brochure. It contains the main property information and overview.</p>
|
|
<div class="image-placeholder">Property Image 1</div>
|
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
|
|
<p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</p>
|
|
</div>
|
|
<div class="footer">
|
|
<p>Property Details - Page 1</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Page 2 -->
|
|
<div class="page">
|
|
<div class="header">
|
|
<h1>Property Brochure - Page 2</h1>
|
|
</div>
|
|
<div class="content">
|
|
<h2>Property Features</h2>
|
|
<p>This is the second page showcasing the property features and amenities.</p>
|
|
<div class="image-placeholder">Property Image 2</div>
|
|
<ul>
|
|
<li>Modern kitchen with stainless steel appliances</li>
|
|
<li>Hardwood floors throughout</li>
|
|
<li>Central air conditioning</li>
|
|
<li>Private balcony with city views</li>
|
|
<li>In-unit washer and dryer</li>
|
|
</ul>
|
|
<p>Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.</p>
|
|
</div>
|
|
<div class="footer">
|
|
<p>Property Features - Page 2</p>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Page 3 -->
|
|
<div class="page">
|
|
<div class="header">
|
|
<h1>Property Brochure - Page 3</h1>
|
|
</div>
|
|
<div class="content">
|
|
<h2>Contact Information</h2>
|
|
<p>This is the final page with contact information and call-to-action.</p>
|
|
<div class="image-placeholder">Property Image 3</div>
|
|
<h3>Contact Details</h3>
|
|
<p><strong>Phone:</strong> (555) 123-4567</p>
|
|
<p><strong>Email:</strong> info@property.com</p>
|
|
<p><strong>Address:</strong> 123 Property Street, City, State 12345</p>
|
|
<p>Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
|
|
</div>
|
|
<div class="footer">
|
|
<p>Contact Information - Page 3</p>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
</html>
|
|
`;
|
|
|
|
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 };
|