1. 首先,发现pycharm里报错,即:不能打开terminal,这样一来pip安装各种包也无法安装;用以下方法来解决这个问题:
File ---settings---tools ---terminal, 把shell.exe改成cmd.exe然后重启pycharm,再点击terminal,即可正常运行!
image.pngimage.png
2. PDF文件进行split,并按页输出:具体代码如下,只需要改一下原始pdf文件路径和输出位置,点击运行即可!
-
注意:输出文件会存放在制定的output位置!这点务必注意!如果没有设置,则会存在默认工作目录下!
# pdf_splitter.py
import os
from PyPDF2 import PdfFileReader, PdfFileWriter
def pdf_splitter(path):
fname = os.path.splitext(os.path.basename(path))[0]
pdf = PdfFileReader(path)
for page in range(pdf.getNumPages()):
pdf_writer = PdfFileWriter()
pdf_writer.addPage(pdf.getPage(page))
#where to output the results
output_filename = 'C:\\Users\\Administrator\\Desktop\\split\\毛螺菌科文献{}_page_{}.pdf'.format(
fname, page+1)
with open(output_filename, 'wb') as out:
pdf_writer.write(out)
print('Created: {}'.format(output_filename))
if __name__ == '__main__':
#original PDF file to be splitted
path = 'C:\\Users\\Administrator\\Desktop\\毛螺菌科文献.pdf'
pdf_splitter(path)
运行前:
image.png运行后:
image.png-
Reference:
https://www.blog.pythonlibrary.org/2018/04/11/splitting-and-merging-pdfs-with-python/
网友评论