-
Notifications
You must be signed in to change notification settings - Fork 2
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
Showing
2 changed files
with
26 additions
and
1 deletion.
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,21 @@ | ||
from pikepdf import Pdf | ||
|
||
def split(doc: BinaryIO, page: int) -> Tuple[Pdf, Pdf]: | ||
""" | ||
Split a PDF document at a specific page number. | ||
:param doc: The PDF document to split. | ||
:param page: The page number to split at. Pages before and including this page will be in the first document, and pages after will be in the second document. | ||
:return: A tuple containing the two split PDF documents. | ||
""" | ||
pdf = Pdf.open(doc) | ||
pdf_a = Pdf.new() | ||
pdf_b = Pdf.new() | ||
|
||
for i, page in enumerate(pdf.pages): | ||
if i < page: | ||
pdf_a.pages.append(page) | ||
else: | ||
pdf_b.pages.append(page) | ||
|
||
return pdf_a, pdf_b |