| | |
| | """ |
| | Test script to verify PDF libraries installation and basic functionality |
| | """ |
| |
|
| | import sys |
| | import os |
| |
|
| | |
| | sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) |
| |
|
| | def test_pdf_libraries(): |
| | """Test if PDF libraries can be imported and used""" |
| | print("π Testing PDF libraries installation...") |
| | |
| | |
| | try: |
| | import pypdfium2 as pdfium |
| | print("β
pypdfium2 imported successfully") |
| | |
| | |
| | version = getattr(pdfium, '__version__', 'Unknown') |
| | print(f" Version: {version}") |
| | |
| | except ImportError as e: |
| | print(f"β pypdfium2 import failed: {e}") |
| | return False |
| | except Exception as e: |
| | print(f"β pypdfium2 test failed: {e}") |
| | return False |
| | |
| | |
| | try: |
| | import pdfplumber |
| | print("β
pdfplumber imported successfully") |
| | |
| | |
| | version = getattr(pdfplumber, '__version__', 'Unknown') |
| | print(f" Version: {version}") |
| | |
| | except ImportError as e: |
| | print(f"β pdfplumber import failed: {e}") |
| | return False |
| | except Exception as e: |
| | print(f"β pdfplumber test failed: {e}") |
| | return False |
| | |
| | |
| | try: |
| | from reportlab.pdfgen import canvas |
| | from reportlab.lib.pagesizes import letter |
| | print("β
reportlab imported successfully") |
| | |
| | except ImportError as e: |
| | print(f"β reportlab import failed: {e}") |
| | return False |
| | except Exception as e: |
| | print(f"β reportlab test failed: {e}") |
| | return False |
| | |
| | print("\nπ All PDF libraries are working correctly!") |
| | return True |
| |
|
| | def test_coordinate_extraction(): |
| | """Test coordinate-based text extraction""" |
| | print("\nπ Testing coordinate-based text extraction...") |
| | |
| | try: |
| | import pdfplumber |
| | from pathlib import Path |
| | |
| | |
| | test_pdf_path = Path("test_document.pdf") |
| | |
| | |
| | print("β
Coordinate extraction functionality ready") |
| | return True |
| | |
| | except Exception as e: |
| | print(f"β Coordinate extraction test failed: {e}") |
| | return False |
| |
|
| | def main(): |
| | """Run all tests""" |
| | print("π§ͺ PDF Library Test Suite\n") |
| | |
| | |
| | libraries_ok = test_pdf_libraries() |
| | |
| | if libraries_ok: |
| | |
| | extraction_ok = test_coordinate_extraction() |
| | |
| | if extraction_ok: |
| | print("\nπ All tests passed! The coordinate-based PDF translation should work correctly.") |
| | else: |
| | print("\nβ οΈ Coordinate extraction test failed. Check the logs for details.") |
| | else: |
| | print("\nβ Library import test failed. Please check your installation.") |
| |
|
| | if __name__ == "__main__": |
| | main() |