Clean up: Remove test_pdftk.php development file
This commit is contained in:
parent
18e5a68b7b
commit
489678ed81
150
test_pdftk.php
150
test_pdftk.php
@ -1,150 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* PDFTK Test Script
|
||||
* This script tests if pdftk is properly installed and working
|
||||
*/
|
||||
|
||||
// Load Dolibarr environment
|
||||
if (file_exists('../../main.inc.php')) {
|
||||
$res = @include '../../main.inc.php';
|
||||
} elseif (file_exists('../../../main.inc.php')) {
|
||||
$res = @include '../../../main.inc.php';
|
||||
} else {
|
||||
$res = 0;
|
||||
}
|
||||
|
||||
if (!$res) {
|
||||
die("Include of main fails");
|
||||
}
|
||||
|
||||
echo "<h2>PDFTK Installation Test</h2>";
|
||||
|
||||
// Test 1: Check if pdftk is available
|
||||
echo "<h3>1. Checking PDFTK Availability</h3>";
|
||||
$pdftk_path = shell_exec('which pdftk 2>/dev/null');
|
||||
if (!empty(trim($pdftk_path))) {
|
||||
echo "<p>✅ PDFTK found at: " . trim($pdftk_path) . "</p>";
|
||||
} else {
|
||||
echo "<p>❌ PDFTK not found. Please install PDFTK first.</p>";
|
||||
echo "<p>See installation guide: <a href='docs/PDFTK_INSTALLATION.md'>PDFTK_INSTALLATION.md</a></p>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Test 2: Check pdftk version
|
||||
echo "<h3>2. Checking PDFTK Version</h3>";
|
||||
$version = shell_exec('pdftk --version 2>&1');
|
||||
if (!empty($version)) {
|
||||
echo "<p>✅ PDFTK version: " . trim($version) . "</p>";
|
||||
} else {
|
||||
echo "<p>❌ Could not get PDFTK version</p>";
|
||||
}
|
||||
|
||||
// Test 3: Check if custom template exists
|
||||
echo "<h3>3. Checking Custom Template</h3>";
|
||||
$custom_template = DOL_DOCUMENT_ROOT.'/custom/declarationtva/templates/declarationtva/ca3_custom_template.pdf';
|
||||
if (file_exists($custom_template)) {
|
||||
echo "<p>✅ Custom template found: " . basename($custom_template) . "</p>";
|
||||
} else {
|
||||
echo "<p>❌ Custom template not found. Please upload your fillable PDF first.</p>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Test 4: Test PDF form field detection
|
||||
echo "<h3>4. Testing PDF Form Field Detection</h3>";
|
||||
$command = "pdftk \"$custom_template\" dump_data_fields 2>&1";
|
||||
$fields_output = shell_exec($command);
|
||||
|
||||
if (!empty($fields_output) && strpos($fields_output, 'FieldName:') !== false) {
|
||||
echo "<p>✅ PDF form fields detected:</p>";
|
||||
echo "<pre>" . htmlspecialchars($fields_output) . "</pre>";
|
||||
} else {
|
||||
echo "<p>❌ No form fields detected or error occurred:</p>";
|
||||
echo "<pre>" . htmlspecialchars($fields_output) . "</pre>";
|
||||
}
|
||||
|
||||
// Test 5: Create a test FDF file
|
||||
echo "<h3>5. Testing FDF File Creation</h3>";
|
||||
$test_fdf = sys_get_temp_dir() . '/test_ca3_' . uniqid() . '.fdf';
|
||||
$fdf_content = "%FDF-1.2\n";
|
||||
$fdf_content .= "1 0 obj\n";
|
||||
$fdf_content .= "<<\n";
|
||||
$fdf_content .= "/FDF\n";
|
||||
$fdf_content .= "<<\n";
|
||||
$fdf_content .= "/Fields [\n";
|
||||
$fdf_content .= "<<\n";
|
||||
$fdf_content .= "/T (company_name)\n";
|
||||
$fdf_content .= "/V (Test Company)\n";
|
||||
$fdf_content .= ">>\n";
|
||||
$fdf_content .= "<<\n";
|
||||
$fdf_content .= "/T (A1_amount)\n";
|
||||
$fdf_content .= "/V (1234.56)\n";
|
||||
$fdf_content .= ">>\n";
|
||||
$fdf_content .= "]\n";
|
||||
$fdf_content .= ">>\n";
|
||||
$fdf_content .= ">>\n";
|
||||
$fdf_content .= "endobj\n";
|
||||
$fdf_content .= "trailer\n";
|
||||
$fdf_content .= "<<\n";
|
||||
$fdf_content .= "/Root 1 0 R\n";
|
||||
$fdf_content .= ">>\n";
|
||||
$fdf_content .= "%%EOF\n";
|
||||
|
||||
if (file_put_contents($test_fdf, $fdf_content)) {
|
||||
echo "<p>✅ Test FDF file created: " . basename($test_fdf) . "</p>";
|
||||
} else {
|
||||
echo "<p>❌ Failed to create FDF file</p>";
|
||||
exit;
|
||||
}
|
||||
|
||||
// Test 6: Test PDF form filling
|
||||
echo "<h3>6. Testing PDF Form Filling</h3>";
|
||||
$test_output = sys_get_temp_dir() . '/test_output_' . uniqid() . '.pdf';
|
||||
$command = "pdftk \"$custom_template\" fill_form \"$test_fdf\" output \"$test_output\" 2>&1";
|
||||
$result = shell_exec($command);
|
||||
|
||||
if (file_exists($test_output) && filesize($test_output) > 0) {
|
||||
echo "<p>✅ PDF form filling successful!</p>";
|
||||
echo "<p>Output file: " . basename($test_output) . " (" . filesize($test_output) . " bytes)</p>";
|
||||
|
||||
// Clean up test files
|
||||
unlink($test_fdf);
|
||||
unlink($test_output);
|
||||
} else {
|
||||
echo "<p>❌ PDF form filling failed:</p>";
|
||||
echo "<pre>" . htmlspecialchars($result) . "</pre>";
|
||||
|
||||
// Clean up test files
|
||||
if (file_exists($test_fdf)) unlink($test_fdf);
|
||||
if (file_exists($test_output)) unlink($test_output);
|
||||
}
|
||||
|
||||
// Test 7: Check module integration
|
||||
echo "<h3>7. Module Integration Test</h3>";
|
||||
try {
|
||||
// Test the module's pdftk detection
|
||||
$pdf_class = new DeclarationTVA_PDF($db);
|
||||
$reflection = new ReflectionClass($pdf_class);
|
||||
$method = $reflection->getMethod('isPdftkAvailable');
|
||||
$method->setAccessible(true);
|
||||
$is_available = $method->invoke($pdf_class);
|
||||
|
||||
if ($is_available) {
|
||||
echo "<p>✅ Module can detect PDFTK</p>";
|
||||
} else {
|
||||
echo "<p>❌ Module cannot detect PDFTK</p>";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "<p>❌ Module integration test failed: " . $e->getMessage() . "</p>";
|
||||
}
|
||||
|
||||
echo "<h3>Summary</h3>";
|
||||
echo "<p>If all tests pass, PDFTK is properly installed and the module should work correctly.</p>";
|
||||
echo "<p>If any tests fail, please check the installation guide and troubleshoot accordingly.</p>";
|
||||
|
||||
echo "<h3>Next Steps</h3>";
|
||||
echo "<ol>";
|
||||
echo "<li>Try the PDF export functionality in the module</li>";
|
||||
echo "<li>Check if form fields are properly filled</li>";
|
||||
echo "<li>Verify the output PDF contains the expected data</li>";
|
||||
echo "</ol>";
|
||||
?>
|
||||
Loading…
Reference in New Issue
Block a user