feat: add support for legacy binary office formats#3804
Open
ceberam wants to merge 3 commits into
Open
Conversation
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
Contributor
|
✅ DCO Check Passed Thanks @ceberam, all your commits are properly signed off. 🎉 |
Contributor
Merge Protections🔴 1 of 2 protections blocking · waiting on 👀 reviews
🔴 Require two reviewer for test updatesWaiting for
This rule is failing.When test data is updated, we require two reviewers
Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Signed-off-by: Cesar Berrospi Ramis <ceb@zurich.ibm.com>
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.
Summary
Add support for legacy binary Office formats -
.doc(Word 97–2004),.xls(Excel 97–2004), and.ppt(PowerPoint 97–2003) - by converting them to their modern Open XML equivalents via LibreOffice before delegating to the existingMsWordDocumentBackend,MsExcelDocumentBackend, andMsPowerpointDocumentBackendparsers.Resolves #1133
Motivation
Docling already supports
.docx,.xlsx, and.pptx. Many real-world document collections still contain the older binary formats, which share the same logical structure. LibreOffice is already an optional dependency used elsewhere in Docling (EMF/WMF image rendering, chart rendering), so reusing it here keeps the dependency footprint unchanged.Changes
New
convert_to_modern_formatutilityShared helper that invokes LibreOffice headless to convert a legacy file (accepted as either a
Pathor aBytesIOstream) to a modern Open XML format and returns aBytesIObuffer.Cleans up its temporary directory in all cases.
Extended backends
Each of the three existing backends gains support for its legacy counterpart:
MsWordDocumentBackendInputFormat.DOC(.doc,.dot)MsExcelDocumentBackendInputFormat.XLS(.xls,.xlt)MsPowerpointDocumentBackendInputFormat.PPT(.ppt,.pot,.pps)When
in_doc.formatis a legacy format,__init__callsconvert_to_modern_formatbefore the normal parsing path runs. No new backend classes are introduced.Format registration
InputFormat.DOC,InputFormat.XLS,InputFormat.PPTadded to theInputFormatenum.FormatToExtensionsandFormatToMimeTypeinbase_models.py(official MIME types:application/msword,application/vnd.ms-excel,application/vnd.ms-powerpoint)._mime_from_extensionindocument.pyupdated to handle the new extensions._get_default_optionindocument_converter.pymaps each legacy format to the sameFormatOptionas its modern counterpart.Correct
DocumentOrigin.mimetypeAll three backends'
convert()methods previously hardcoded the modern MIME type. They now useFormatToMimeType[self.input_format][0], so a.docfile producesmimetype="application/msword"inDocumentOriginrather than the MIME type of the converted intermediate. All three legacy MIME types are alreadyaccepted by
DocumentOrigin's validator via Python's standardmimetypesmodule — no changes todocling-coreare required.Documentation
docs/usage/supported_formats.md— new row forDOC, XLS, PPTin the supported input formats table.pyproject.toml— updated comment on theformat-officeextras block.Limitations
PATH(or at the standard macOSlocation). Conversion raises
RuntimeErrorwhen it is not available; theend-to-end tests are automatically skipped.
Checklist: