好友
阅读权限10
听众
最后登录1970-1-1
|
本帖最后由 苏紫方璇 于 2023-11-26 14:07 编辑
pdf工具,之前写的合并工具有点麻烦,使用PyQt5库重写合并拆分和删除指定页面的程序
[md]```
import sys
import os
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton, QVBoxLayout, QWidget, QFileDialog, QListWidget, QMessageBox, QLineEdit, QHBoxLayout, QInputDialog
from PyQt5.QtCore import Qt, QThread, pyqtSignal
from PyPDF2 import PdfReader, PdfWriter, PdfMerger
from PyQt5 import QtGui
class CustomListWidget(QListWidget):
def __init__(self, parent=None):
super().__init__(parent)
class Worker(QThread):
finished = pyqtSignal(str)
error = pyqtSignal(str)
def __init__(self, pdf_files, range_str=None, save_path=None, operation=None):
super().__init__()
self.pdf_files = pdf_files
self.range_str = range_str
self.save_path = save_path
self.operation = operation
def run(self):
try:
if self.operation == 'merge':
merger = PdfMerger()
for pdf in self.pdf_files:
merger.append(pdf)
merger.write(self.save_path)
merger.close()
self.finished.emit('PDF文件已成功合并。')
elif self.operation == 'split':
start_page, end_page = self.parse_range(self.range_str)
reader = PdfReader(self.pdf_files[0])
os.makedirs(self.save_path, exist_ok=True)
for page in range(start_page, end_page + 1):
writer = PdfWriter()
writer.add_page(reader.pages |
免费评分
-
查看全部评分
|
发帖前要善用【论坛搜索】功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。 |
|
|
|
|