jzhg

需求:

环境准备:

1、Pyhon3以上+PyPDF2 

2、代码与需要分割的PDF放在同一目录下

代码如下(简版):

from PyPDF2 import PdfFileReader, PdfFileWriter
import os
def pdf_splitter(path,start,end):
    fname = os.path.splitext(os.path.basename(path))[0]
    pdf = PdfFileReader(path)
    pdf_writer = PdfFileWriter()
    output_filename = \'{}_page_{}.pdf\'.format(start,end)
    for page in range(start,end):        
        pdf_writer.addPage(pdf.getPage(page))
        print(page)
    
    with open(output_filename,\'wb\') as out:
        pdf_writer.write(out)
        print(\'Created:{}\'.format(output_filename))

start = 23
end = 34
path = \'2.pdf\'
pdf_splitter(path,start,end)
        

  

过程中遇到的问题:

1、PdfReadError: File has not been decrypted

解决方案:

    参考链接:https://blog.csdn.net/xunmengpiaoyun/article/details/83146125

 

相关链接:https://blog.csdn.net/Leafage_M/article/details/79705731

分类:

技术点:

相关文章:

  • 2021-06-25
  • 2021-12-04
  • 2021-12-14
  • 2021-05-07
  • 2021-10-19
  • 2022-01-01
  • 2021-11-04
猜你喜欢
  • 2021-12-28
  • 2021-09-04
  • 2022-01-01
  • 2021-12-14
  • 2021-08-31
相关资源
相似解决方案