Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit97bf116

Browse files
committed
Add solution to ch13 section 3 exercise 1
1 parent822426a commit97bf116

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed
Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,29 @@
1-
# 13.2 - Concatenating and Merging PDFs
1+
# 13.3 - Concatenating and Merging PDFs
22
# Solutions to review exercises
3+
4+
# ***********
5+
# Exercise 1
6+
#
7+
# In the Chapter 13 Practice Files directory there are three PDFs called
8+
# `merge1.pdf`, `merge2.pdf`, and `merge3.pdf`. Using a `PdfFileMerger`
9+
# instance, concatenate the two files `merge1.pdf` and `merge2.pdf`
10+
# using`.append()`.
11+
# ***********
12+
13+
frompathlibimportPath
14+
15+
fromPyPDF2importPdfFileMerger
16+
17+
18+
BASE_PATH=Path.home()/"github/realpython/python-basics-exercises/" \
19+
"ch13-interact-with-pdf-files/practice_files"
20+
21+
pdf_paths= [BASE_PATH/"merge1.pdf",BASE_PATH/"merge2.pdf"]
22+
pdf_merger=PdfFileMerger()
23+
24+
forpathinpdf_paths:
25+
pdf_merger.append(str(path))
26+
27+
output_path=Path.home()/"concatenated.pdf"
28+
withoutput_path.open(mode="wb")asoutput_file:
29+
pdf_merger.write(output_file)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp