Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mikes zhang
001
提交
8954d6ee
0
001
项目概览
mikes zhang
/
001
通知
6
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
0
001
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
未验证
提交
8954d6ee
编写于
5月 13, 2020
作者:
D
David Amos
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add # noqa to quiet linter
上级
e30b5681
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
21 addition
and
21 deletion
+21
-21
creating-and-modifying-pdfs/source_code/01-extracting-text-from-a-pdf.py
...difying-pdfs/source_code/01-extracting-text-from-a-pdf.py
+2
-2
creating-and-modifying-pdfs/source_code/02-extracting-pages-from-a-pdf.py
...ifying-pdfs/source_code/02-extracting-pages-from-a-pdf.py
+5
-5
creating-and-modifying-pdfs/source_code/03-concatenating-and-merging-pdfs.py
...ing-pdfs/source_code/03-concatenating-and-merging-pdfs.py
+3
-3
creating-and-modifying-pdfs/source_code/04-rotating-and-cropping-PDF-pages.py
...ng-pdfs/source_code/04-rotating-and-cropping-PDF-pages.py
+3
-3
creating-and-modifying-pdfs/source_code/05-encrypting-and-decrypting-pdfs.py
...ing-pdfs/source_code/05-encrypting-and-decrypting-pdfs.py
+2
-2
creating-and-modifying-pdfs/source_code/06-creating-a-pdf-file-from-scratch.py
...g-pdfs/source_code/06-creating-a-pdf-file-from-scratch.py
+6
-6
未找到文件。
creating-and-modifying-pdfs/source_code/01-extracting-text-from-a-pdf.py
浏览文件 @
8954d6ee
...
...
@@ -41,8 +41,8 @@ for page in pdf.pages:
# Putting It All Together
# -----------------------
from
pathlib
import
Path
from
PyPDF2
import
PdfFileReader
from
pathlib
import
Path
# noqa
from
PyPDF2
import
PdfFileReader
# noqa
# Change the path below to the correct path for your computer.
pdf_path
=
(
...
...
creating-and-modifying-pdfs/source_code/02-extracting-pages-from-a-pdf.py
浏览文件 @
8954d6ee
...
...
@@ -10,7 +10,7 @@ page = pdf_writer.addBlankPage(width=72, height=72)
print
(
type
(
page
))
from
pathlib
import
Path
from
pathlib
import
Path
# noqa
with
Path
(
"blank.pdf"
).
open
(
mode
=
"wb"
)
as
output_file
:
pdf_writer
.
write
(
output_file
)
...
...
@@ -20,8 +20,8 @@ with Path("blank.pdf").open(mode="wb") as output_file:
# Extracting a Single Page From a PDF
# -----------------------------------
from
pathlib
import
Path
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
from
pathlib
import
Path
# noqa
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
# noqa
# Change the path to work on your computer if necessary
pdf_path
=
(
...
...
@@ -45,8 +45,8 @@ with Path("first_page.pdf").open(mode="wb") as output_file:
# Extracting Multiple Pages From a PDF
# ------------------------------------
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
from
pathlib
import
Path
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
# noqa
from
pathlib
import
Path
# noqa
pdf_path
=
(
Path
.
home
()
...
...
creating-and-modifying-pdfs/source_code/03-concatenating-and-merging-pdfs.py
浏览文件 @
8954d6ee
...
...
@@ -10,7 +10,7 @@ pdf_merger = PdfFileMerger()
# Concatenating PDFs With .append()
# ---------------------------------
from
pathlib
import
Path
from
pathlib
import
Path
# noqa
reports_dir
=
(
Path
.
home
()
...
...
@@ -39,8 +39,8 @@ with Path("expense_reports.pdf").open(mode="wb") as output_file:
# Merging PDFs With .merge()
# --------------------------
from
pathlib
import
Path
from
PyPDF2
import
PdfFileMerger
from
pathlib
import
Path
# noqa
from
PyPDF2
import
PdfFileMerger
# noqa
report_dir
=
(
Path
.
home
()
...
...
creating-and-modifying-pdfs/source_code/04-rotating-and-cropping-PDF-pages.py
浏览文件 @
8954d6ee
...
...
@@ -53,8 +53,8 @@ with Path("ugly_rotated2.pdf").open(mode="wb") as output_file:
# Cropping Pages
# --------------
from
pathlib
import
Path
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
from
pathlib
import
Path
# noqa
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
# noqa
pdf_path
=
(
Path
.
home
()
...
...
@@ -88,7 +88,7 @@ pdf_writer = PdfFileWriter()
first_page
=
pdf_reader
.
getPage
(
0
)
import
copy
import
copy
# noqa
left_side
=
copy
.
deepcopy
(
first_page
)
current_coords
=
left_side
.
mediaBox
.
upperRight
...
...
creating-and-modifying-pdfs/source_code/05-encrypting-and-decrypting-pdfs.py
浏览文件 @
8954d6ee
...
...
@@ -32,8 +32,8 @@ pdf_writer.encrypt(user_pwd=user_pwd, owner_pwd=owner_pwd)
# Decrypting PDFs
# ---------------
from
pathlib
import
Path
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
from
pathlib
import
Path
# noqa
from
PyPDF2
import
PdfFileReader
,
PdfFileWriter
# noqa
pdf_path
=
Path
.
home
()
/
"newsletter_protected.pdf"
...
...
creating-and-modifying-pdfs/source_code/06-creating-a-pdf-file-from-scratch.py
浏览文件 @
8954d6ee
...
...
@@ -13,14 +13,14 @@ canvas.save()
# Setting the Page Size
# ---------------------
from
reportlab.lib.units
import
inch
,
cm
from
reportlab.lib.units
import
inch
,
cm
# noqa
print
(
cm
)
print
(
inch
)
canvas
=
Canvas
(
"hello.pdf"
,
pagesize
=
(
8.5
*
inch
,
11
*
inch
))
from
reportlab.lib.pagesizes
import
LETTER
from
reportlab.lib.pagesizes
import
LETTER
# noqa
canvas
=
Canvas
(
"hello.pdf"
,
pagesize
=
LETTER
)
print
(
LETTER
)
...
...
@@ -36,10 +36,10 @@ canvas.drawString(1 * inch, 10 * inch, "Times New Roman (18 pt)")
canvas
.
save
()
# The code below creates a PDF with blue text
from
reportlab.lib.colors
import
blue
from
reportlab.lib.pagesizes
import
LETTER
from
reportlab.lib.units
import
inch
from
reportlab.pdfgen.canvas
import
Canvas
from
reportlab.lib.colors
import
blue
# noqa
from
reportlab.lib.pagesizes
import
LETTER
# noqa
from
reportlab.lib.units
import
inch
# noqa
from
reportlab.pdfgen.canvas
import
Canvas
# noqa
canvas
=
Canvas
(
"font-colors.pdf"
,
pagesize
=
LETTER
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录