python:办公自动化之:PDF

需要模块:pypdf2、pdfplumber

 

Python提取PDF文字内容

利用pdfplumber提取文字:

python:办公自动化之:PDF

import pdfplumber

with pdfplumber.open(....pdf) as pdf:

       first_page=pdf.pages[0]

       print(first_apge.extract_text())

提取表格:

 python:办公自动化之:PDF

table是个列表类型,可以放进pandas

多个表格:page.extract_tables()

python:办公自动化之:PDF:默认

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

去除空行:

python:办公自动化之:PDF

修改以上for语句,加一个判断空行语句,如下

python:办公自动化之:PDF

合并单词:加到上述if语句中

python:办公自动化之:PDF

Python语法知识点:

行内条件判断

python:办公自动化之:PDF


利用pypdf2分割pdf

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

        with open(f'./分割后PDF文件/filename{page}.pdf','wb') as out:

                pdf_writer.write(out)

将上面分割的pdf再合并成一个:

python:办公自动化之:PDF

pdf_writer=PdfFileWriter()

for page in range(16):

     pdf_reader=PdfFileReader(f'filename{page}.pdf')

     for page in range(pdf_reader.getNumPages()):

              pdf_writer.addPage(pdf_reader.getPage(page))

      with open('merge.pdf','wb') as out:

             pdf_writer.write(out)

旋转PDF某一页:

python:办公自动化之:PDF

python:办公自动化之:PDF

  排序PDF页面:

以倒序为例:

python:办公自动化之:PDF

python:办公自动化之:PDF


加水印:

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

加解密:

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF

python:办公自动化之:PDF