文献pdf首页提取,做成单独的PDF

如题所示,文献pdf首页提取,做成单独的pdf

  • 主要是为了将搜集到的大量文献的摘要提取出来,通过直接阅读摘要先判断文章需不需要看下去

需要安装的库

pip install pypdf2

在基础的功能上使用tkinter 做了一个界面,方便操作,打包完成后可以直接双击使用。


# -*- coding: utf-8 -*-
"""
Created on Fri Nov  5 15:49:08 2021

@author: zy_win10
"""
import tkinter
from tkinter import filedialog
from tkinter import *
from PyPDF2 import PdfFileWriter, PdfFileReader
import os
from tkinter import messagebox
# 打开文件夹选择框
def helloCallBack():
    file_path = filedialog.askdirectory()
    e.set(file_path)
    # 这里其实是默认选择之后直接进行转换的 如果不想直接转换,可以将下面这一句注释掉
    g_pdf()

def g_pdf():
    
    try:
        fl = os.listdir(e.get())
        # print(fl)
        output = PdfFileWriter()
        for item in fl:
            if '.pdf' in item:
                pdf_file = PdfFileReader(open(os.path.join(e.get(),item), "rb"))
                output.addPage(pdf_file.getPage(0))
        import time
        ofn = 'output'+str(time.time())+'.pdf'
        print(ofn)
        outputStream = open(os.path.join(e.get(),ofn), "wb")
        output.write(outputStream)
        messagebox.showinfo('ok','转换完成')
    # print('ok')
    except Exception as ee:
    	# 实际情况下也会有很多时候运行不出来,这里直接报编码错误
        messagebox.showinfo('error','请保证pdf文件内容 名称及路径均没有中文') 
top = tkinter.Tk()
# 进入消息循环
top.geometry("200x100")
button2 = Button(top, text='生成pdf', command=g_pdf)
B = tkinter.Button(top, text ="选择文件夹", command = helloCallBack)
e = StringVar()
B.pack()
button2.pack()
top.mainloop()

  • 代码东拼西凑的,有我之前写的一些程序,也有从网上其它博客找到的。出处可能找到不到了,如果需要引用可以告知。

生成exe

  • 使用pyinstaller 生成即可。

Gitee 链接 在里面可以找到生成好的exe 可以直接使用

包含生成好的exe

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值