-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add reader.attachments public interface (#1661)
Add `PdfReader.attachments -> Mapping[str, List[bytes]] as a public interface. The heavy-lifting was done by @pubpub-zz in #1611 . This PR only adds the interface for the exiting functions.
- Loading branch information
1 parent
67b085b
commit d343445
Showing
4 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Extract Attachments | ||
|
||
PDF documents can contain attachments. Attachments have a name, but it might not | ||
be unique. For this reason, the value of `reader.attachments["attachment_name"]` | ||
is a list. | ||
|
||
You can extract all attachments like this: | ||
|
||
```python | ||
from pypdf import PdfReader | ||
|
||
reader = PdfReader("example.pdf") | ||
|
||
for name, content_list in reader.attachments: | ||
for i, content in enumerate(content_list): | ||
with open(f"{name}-{i}", "wb") as fp: | ||
fp.write(content) | ||
``` |
This file contains 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
This file contains 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