Container-aware parsing lets you open archive-like formats (ZIP, RAR, 7z, TAR), Outlook stores (PST/OST), PDF portfolios, and email attachments, then process their contents using the same parser API.
Iterate nested items safely
fromgroupdocs.parserimportParserfromgroupdocs.parser.exceptionsimportUnsupportedDocumentFormatExceptiondefprint_text(item_path,parser):reader=parser.get_text()text=reader.read_to_end()ifreaderisnotNoneelseNoneprint(f"{item_path}: {textiftextelse'[no text]'}")withParser("portfolio.pdf")asparser:container=parser.get_container()ifcontainerisNone:print("Container extraction isn't supported for this format.")else:foritemincontainer:try:withitem.open_parser()asinner_parser:print_text(item.file_path,inner_parser)exceptUnsupportedDocumentFormatException:print(f"{item.file_path}: format is not supported.")
The following sample file is used in this example: portfolio.pdf
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@northwindroasters.e
[TRUNCATED]