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

feat(pdf): improve PDF font subsetting process with subprocess and timeout handling #123

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

awwaawwa
Copy link
Member

This PR enhances the PDF creation process in BabelDOC with more robust font subsetting.

Changes:

  • Add subprocess-based font subsetting with timeout protection to prevent hanging
  • Create a dedicated subset_fonts_in_subprocess method that handles process management
  • Implement proper error handling and logging for font subsetting failures
  • Gracefully fall back to the original PDF when subsetting fails
  • Add temporary file handling for input/output during the subsetting process
  • Improve debug information writing with better error handling

Benefits:

  • Prevents the application from hanging indefinitely during font subsetting
  • Improves reliability by adding proper timeout handling (60 seconds)
  • Maintains backward compatibility by falling back to original PDF when needed
  • Enhances user experience by ensuring the PDF generation process completes

These changes make the PDF generation more robust, especially when dealing with complex fonts that might cause subsetting to hang or fail.

…handling

- Implement `subset_fonts_in_subprocess` method to run font subsetting in a separate process
- Add timeout mechanism to prevent long-running font subsetting operations
- Gracefully handle subprocess termination and fallback to original PDF if subsetting fails
- Update PDF creation workflow to use subprocess font subsetting when not skipping clean step
Update version number across project files:
- Increment version in pyproject.toml
- Update __version__ in __init__.py, const.py, and main.py
@awwaawwa awwaawwa merged commit be748e0 into main Feb 27, 2025
10 checks passed
@awwaawwa
Copy link
Member Author

MuPDF's subset_fonts will block all other threads under specific circumstances, so it is executed in a subprocess.

@awwaawwa awwaawwa deleted the fix/subset-fonts-subprocess branch February 27, 2025 12:15
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.

1 participant