ObjDocumentTools provides utility functions and helper methods for document processing, conversion, validation, and analysis.
Module: factory.core/ObjDocumentTools.py
from ObjDocumentTools import DocumentTools
tools = DocumentTools()
# Detect file type
file_type = tools.detect_file_type("/path/to/file.pdf")
print(file_type) # "application/pdf"
# Validate format
is_valid = tools.validate_format(
filename="document.docx",
expected_type="docx"
)
# Get MIME type
mime = tools.get_mime_type("/path/to/image.jpg")
# Convert to PDF
tools.convert_to_pdf(
input_file="document.docx",
output_file="document.pdf"
)
# Extract text
text = tools.extract_text("/path/to/document.pdf")
# Generate thumbnail
tools.generate_thumbnail(
input_file="document.pdf",
output_file="thumbnail.png",
size=(200, 200)
)
# Validate file
validation_result = tools.validate_file(
filepath="/path/to/file.pdf",
max_size_mb=10,
allowed_types=["pdf", "docx"]
)
if validation_result['valid']:
print("File is valid")
else:
print(f"Validation errors: {validation_result['errors']}")
# Check file integrity
is_intact = tools.check_integrity("/path/to/file.pdf")
# Get document stats
stats = tools.get_document_stats("/path/to/document.pdf")
print(f"Pages: {stats['pages']}, Words: {stats['words']}")
# Extract metadata
metadata = tools.extract_metadata("/path/to/document.pdf")
print(f"Author: {metadata['author']}, Created: {metadata['created']}")
# Analyze content
analysis = tools.analyze_content("/path/to/document.txt")
print(f"Language: {analysis['language']}, Sentiment: {analysis['sentiment']}")
python-magic - File type detectionPyPDF2 or pdfplumber - PDF operationsPillow - Image processingpython-docx - Word document handlingObjDocument.py - Document managementObjDocumentVideo.py - Video-specific toolsObjDocumentAudio.py - Audio-specific toolsObjImage.py - Image processing