feat: expose PDF embedded-file attachments on SegmentedPage - #313
feat: expose PDF embedded-file attachments on SegmentedPage#313yonikremer wants to merge 1 commit into
Conversation
|
✅ DCO Check Passed Thanks @yonikremer, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
|
@PeterStaar-IBM Hey, can you review the PR? I think it would be a great feature for docling. |
|
|
||
|
|
||
| class FileAttachmentAnnotation(BaseModel): | ||
| """Position of a FileAttachment annotation on a page (0-based). |
There was a problem hiding this comment.
I think the convention is that in C++ we use 0-based (since vectors are zero based and all memory is stored there), however the python interface should be 1-based (following the PDF convention). The goal of the python is to translate the 1 based to the 0 based.
|
@yonikremer Thanks for the addition, can you:
|
|
I wrote a PR for defining those classes in docling core: docling-project/docling-core#713. Do I need to wait for a new version of docling core or just for the PR merge? |
|
@PeterStaar-IBM I updated the PR |
good, please fix the CI: docling-project/docling-core#713 |
Extract embedded-file attachments (name, MIME, size, page annotations, binary data) from PDFs via qpdf, and expose them through docling-core's FileAttachmentAnnotation/PdfAttachment types. get_attachments() returns PdfAttachment with eagerly-decoded data (200 MB cap; data=None + warning above), and get_page()/iterate_pages() populate page.attachments with the attachments anchored to each page. Requires docling-core >=2.92.0 (core PR #1). Signed-off-by: yoni kremer <yoni.kremer@gmail.com>
b6739d3 to
4a5fdb8
Compare
|
Retrimmed to the small scope agreed with the maintainer (see core #734 design):
Diff is now one commit, 7 files. |
Summary
Extract PDF embedded-file attachments and expose them on the parse-level page model (
SegmentedPdfPage), exactly per the maintainer's direction to split the attachment feature into small PRs.PdfDocument.get_attachments() -> list[PdfAttachment]— eagerly decodes each attachment's binary payload intoPdfAttachment.data, capped at 200 MB. Attachments above the cap (or that fail to decode) are still reported with their metadata butdata=None, plus a warning.PdfDocument.get_page()/get_page_with_timings()/iterate_pages()populatepage.attachments— each page carries thePdfAttachments anchored to it viaFileAttachmentAnnotation(page_no+bbox). Unanchored attachments (fromCatalog/Names/EmbeddedFiles) live only at document level.get_attachment_stream,_AttachmentDeletingFile) are deferred to the docling PR and are NOT part of this one.get_attachment_data(index, *, max_size)stays as the internal decode primitive.This PR hard-depends on docling-project/docling-core#734 — "page-level attachment types".
FileAttachmentAnnotation,PdfAttachment(including thedata: bytesfield), and theattachmentslist onSegmentedPdfPage/ParsedPdfDocumentindocling_core.types.doc.page.PdfAttachment.dataandSegmentedPdfPage.attachments; it does not compile/run against any currently-releaseddocling-core.pyproject.tomldependency is therefore bumped todocling-core>=2.92.0,<3.0.0(the release that ships core PR Add and fix cli #1). CI will not pass until that release exists.Landing order: core #734 → this PR (parse #313) → core
AttachmentItemPR → docling integration.Testing
tests/test_attachments.py(10 tests): binary data onPdfAttachment, 200 MB cap behavior (data=None+ warning above the cap), per-pagepage.attachments(anchored vs unanchored),iterate_pageswiring, empty doc, caching,get_attachment_dataprimitive contract.test_attachments.py+test_parse.py— 31 passed.