-
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.
- Loading branch information
1 parent
9111336
commit 9cd16d0
Showing
4 changed files
with
212 additions
and
3 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
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,22 @@ | ||
# Streaming Data with PyPDF2 | ||
|
||
In some cases you might want to avoid saving things explicitly as a file | ||
to disk, e.g. when you want to store the PDF in a database or AWS S3. | ||
|
||
PyPDF2 supports streaming data to a file-like object and here is how. | ||
|
||
```python | ||
from io import BytesIO | ||
|
||
# Prepare example | ||
with open("example.pdf", 'rb') as fh: | ||
bytes_stream = BytesIO(fh.read()) | ||
|
||
# Read from bytes_stream | ||
reader = PdfFileReader(bytes_stream) | ||
|
||
# Write to bytes_stream | ||
writer = PdfFileWriter() | ||
with BytesIO() as bytes_stream: | ||
writer.write(bytes_stream) | ||
``` |