fix(high_level): gracefully handle subset_fonts failures#1126
Open
octo-patch wants to merge 1 commit intoPDFMathTranslate:mainfrom
Open
fix(high_level): gracefully handle subset_fonts failures#1126octo-patch wants to merge 1 commit intoPDFMathTranslate:mainfrom
octo-patch wants to merge 1 commit intoPDFMathTranslate:mainfrom
Conversation
When PyMuPDF's subset_fonts() raises a ValueError (e.g. due to a bad font width table value in some PDFs), the translation would crash after completing all the actual translation work. Wrap each subset_fonts call in a try-except so the output PDF is still written even if font subsetting fails. The output will be slightly larger in this case. Fixes PDFMathTranslate#975
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #975
Problem
When
doc.subset_fonts(fallback=True)is called during PDF generation, PyMuPDF may raiseValueError: bad 'value'for certain PDFs that have malformed font width tables. This causes the entire translation to crash at the very end — after all translation work has already completed — producing no output file.Stack trace from the issue:
Solution
Wrap each
subset_fonts()call in atry-exceptblock. If font subsetting fails, log a warning and continue — the output PDF is still written successfully. The only downside is a slightly larger file size when font subsetting is skipped.Testing
subset_fontsraises aValueError