File size: 3,047 Bytes
ab208dc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
#!/usr/bin/env python3
"""
Test script to verify PDF libraries installation and basic functionality
"""
import sys
import os
# Add the parent directory to the Python path
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...")
# Test pypdfium2
try:
import pypdfium2 as pdfium
print("β
pypdfium2 imported successfully")
# Test basic functionality
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
# Test pdfplumber
try:
import pdfplumber
print("β
pdfplumber imported successfully")
# Test basic functionality
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
# Test reportlab
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
# Create a simple test PDF
test_pdf_path = Path("test_document.pdf")
# For now, just test the import and basic functionality
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")
# Test library imports
libraries_ok = test_pdf_libraries()
if libraries_ok:
# Test coordinate extraction
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() |