diff --git a/test_pdftk.php b/test_pdftk.php deleted file mode 100644 index 325ca6f..0000000 --- a/test_pdftk.php +++ /dev/null @@ -1,150 +0,0 @@ -PDFTK Installation Test"; - -// Test 1: Check if pdftk is available -echo "

1. Checking PDFTK Availability

"; -$pdftk_path = shell_exec('which pdftk 2>/dev/null'); -if (!empty(trim($pdftk_path))) { - echo "

✅ PDFTK found at: " . trim($pdftk_path) . "

"; -} else { - echo "

❌ PDFTK not found. Please install PDFTK first.

"; - echo "

See installation guide: PDFTK_INSTALLATION.md

"; - exit; -} - -// Test 2: Check pdftk version -echo "

2. Checking PDFTK Version

"; -$version = shell_exec('pdftk --version 2>&1'); -if (!empty($version)) { - echo "

✅ PDFTK version: " . trim($version) . "

"; -} else { - echo "

❌ Could not get PDFTK version

"; -} - -// Test 3: Check if custom template exists -echo "

3. Checking Custom Template

"; -$custom_template = DOL_DOCUMENT_ROOT.'/custom/declarationtva/templates/declarationtva/ca3_custom_template.pdf'; -if (file_exists($custom_template)) { - echo "

✅ Custom template found: " . basename($custom_template) . "

"; -} else { - echo "

❌ Custom template not found. Please upload your fillable PDF first.

"; - exit; -} - -// Test 4: Test PDF form field detection -echo "

4. Testing PDF Form Field Detection

"; -$command = "pdftk \"$custom_template\" dump_data_fields 2>&1"; -$fields_output = shell_exec($command); - -if (!empty($fields_output) && strpos($fields_output, 'FieldName:') !== false) { - echo "

✅ PDF form fields detected:

"; - echo "
" . htmlspecialchars($fields_output) . "
"; -} else { - echo "

❌ No form fields detected or error occurred:

"; - echo "
" . htmlspecialchars($fields_output) . "
"; -} - -// Test 5: Create a test FDF file -echo "

5. Testing FDF File Creation

"; -$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 "

✅ Test FDF file created: " . basename($test_fdf) . "

"; -} else { - echo "

❌ Failed to create FDF file

"; - exit; -} - -// Test 6: Test PDF form filling -echo "

6. Testing PDF Form Filling

"; -$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 "

✅ PDF form filling successful!

"; - echo "

Output file: " . basename($test_output) . " (" . filesize($test_output) . " bytes)

"; - - // Clean up test files - unlink($test_fdf); - unlink($test_output); -} else { - echo "

❌ PDF form filling failed:

"; - echo "
" . htmlspecialchars($result) . "
"; - - // 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 "

7. Module Integration Test

"; -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 "

✅ Module can detect PDFTK

"; - } else { - echo "

❌ Module cannot detect PDFTK

"; - } -} catch (Exception $e) { - echo "

❌ Module integration test failed: " . $e->getMessage() . "

"; -} - -echo "

Summary

"; -echo "

If all tests pass, PDFTK is properly installed and the module should work correctly.

"; -echo "

If any tests fail, please check the installation guide and troubleshoot accordingly.

"; - -echo "

Next Steps

"; -echo "
    "; -echo "
  1. Try the PDF export functionality in the module
  2. "; -echo "
  3. Check if form fields are properly filled
  4. "; -echo "
  5. Verify the output PDF contains the expected data
  6. "; -echo "
"; -?>