Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Error Handling and PDF Processing in pdf_util.py and pdf_compiler.py #5

Merged
merged 4 commits into from
Nov 20, 2024

Conversation

RossLux
Copy link
Contributor

@RossLux RossLux commented Nov 20, 2024

This pull request introduces several enhancements and bug fixes to the PDF processing utilities within the pdf_util.py and pdf_compiler.py modules.

Key Changes

  1. Enhanced Error Handling in RTF to PDF Conversion
    Retry Logic: The rtf_file_to_pdf method now includes a retry mechanism that attempts to convert RTF files to PDF up to three times before reporting a failure. This addresses intermittent issues with Word automation where conversions might fail randomly.
    Process Cleanup: Improved the cleanup process by ensuring that Word instances are properly closed after each attempt, preventing orphaned processes that could consume system resources.
  2. Improved Word Process Termination
    Refined close_word_proc Method: Modified this method to handle process termination more gracefully. It now attempts to kill Word-related processes within a try-except block, ensuring that exceptions are caught and handled without crashing the application.
    Interactive and Silent Modes: The method now distinguishes between silent mode and interactive mode, asking the user for confirmation in interactive mode before terminating processes.
  3. Enhanced PDF Combining Logic
    New _fitz_combine Method: Added a helper method to streamline the PDF combining process using PyMuPDF (fitz). This method handles bookmarks, table of contents, and encryption more effectively.
    Conditional TOC Addition: The addition of the Table of Contents is now conditional, only occurring if PDFs were successfully combined. This prevents errors when there are no PDFs to combine.
  4. Logging and Feedback Improvements
    Detailed Logging: Updated logging messages to provide clearer and more informative feedback, including the number of files processed and successfully added to the combined PDF.
    User Notifications: Enhanced user notifications for successful operations and error conditions, making it easier to understand the process flow and troubleshoot issues.
  5. Code Cleanup and Optimization
    Data Processing: Simplified data handling using pandas DataFrames, improving code readability and performance.
    Removed Redundancies: Eliminated unnecessary code segments, such as unused variables and redundant loops.
    Error Messages: Standardized error messages for consistency and clarity.
    Testing and Validation
    RTF to PDF Conversion: Verified that RTF files are correctly converted to PDFs, and the retry logic effectively handles intermittent failures.
    Process Termination: Confirmed that Word processes are terminated appropriately after conversions, both in silent and interactive modes.
    PDF Combining: Tested the PDF combining process with various datasets to ensure bookmarks and TOC are correctly handled.
    Logging Output: Reviewed logging outputs to ensure messages are accurate and helpful for end-users.

@RossLux RossLux self-assigned this Nov 20, 2024
@RossLux RossLux merged commit 0e4ae71 into main Nov 20, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants