pypdf2 存储pdf_PyPDF2:用于PDF文件操作的Python库

pypdf2 存储pdf

PyPDF2 is a pure-python library to work with PDF files. We can use the PyPDF2 module to work with the existing PDF files. We can’t create a new PDF file using this module.

PyPDF2是一个纯Python库,可处理PDF文件。 我们可以使用PyPDF2模块来处理现有的PDF文件。 我们无法使用此模块创建新的PDF文件。

PyPDF2功能 (PyPDF2 Features)

Some of the exciting features of PyPDF2 module are:

PyPDF2模块的一些令人兴奋的功能包括:

  • PDF Files metadata such as number of pages, author, creator, created and last updated time.

    PDF文件元数据,例如页数,作者,创建者,创建时间和上次更新时间。
  • Extracting Content of PDF file page by page.

    逐页提取PDF文件的内容。
  • Merge multiple PDF files.

    合并多个PDF文件。
  • Rotate PDF file pages by an angle.

    将PDF文件页面旋转一个角度。
  • Scaling of PDF pages.

    PDF页面缩放。
  • Extracting images from PDF pages and saving as image using the Pillow library.

    从PDF页面提取图像并使用Pillow库保存为图像。

安装PyPDF2模块 (Installing PyPDF2 Module)

We can use PIP to install PyPDF2 module.

我们可以使用PIP来安装PyPDF2模块。

$ pip install PyPDF2

PyPDF2范例 (PyPDF2 Examples)

Let’s look at some examples to work with PDF files using the PyPDF2 module.

让我们看一些使用PyPDF2模块处理PDF文件的示例。

1.提取PDF元数据 (1. Extracting PDF Metadata)

We can get the number of pages in the PDF file. We can also get the information about the PDF author, creator app, and creation dates.

我们可以在PDF文件中获取页数。 我们还可以获得有关PDF作者,创建者应用程序和创建日期的信息。

import PyPDF2

with open('Python_Tutorial.pdf', 'rb') as pdf_file:
    pdf_reader = PyPDF2.PdfFileReader(pdf_file)
    print(f'Number of Pages in PDF File is {pdf_reader.getNumPages()}')
    print(f'PDF Metadata is {pdf_reader.documentInfo}')
    print(f'PDF File Author is {pdf_reader.documentInfo["/Author"]}')
    print(f'PDF File Creator is {pdf_reader.documentInfo["/Creator"]}')

Sample Output:

样本输出:

Number of Pages in PDF File is 2
PDF Metad
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值