Extract Data from Attachments and ZIP Archives
Leave feedback
On this page
Use container extraction to open archive-like formats (ZIP, RAR, TAR), Outlook stores (PST/OST), PDF portfolios, and email attachments, then parse their contents.
Extract and parse attachments
fromgroupdocs.parserimportParserfromgroupdocs.parser.exceptionsimportUnsupportedDocumentFormatExceptionwithParser("./archive.zip")asparser:attachments=parser.get_container()ifattachmentsisNone:print("Container extraction isn't supported for this format.")else:foriteminattachments:print(item.file_path)try:withitem.open_parser()asattachment_parser:reader=attachment_parser.get_text()print(reader.read_to_end()ifreaderisnotNoneelse"No text available.")exceptUnsupportedDocumentFormatException:print("Item format is not supported.")
The following sample file is used in this example: archive.zip
finance/invoice-HLP-2025-0412.pdf
INVOICE
FROM Invoice Number HLP-2025-0412
Northwind Coffee Roasters Invoice Date 4 November 2025
4 Roastery Lane, Millbrook Due Date 4 December 2025
alex.chen@northwindroa
[TRUNCATED]
For each item, use open_parser() to create a Parser over the embedded content and reuse standard extraction methods (get_text, get_images, get_metadata, etc.).