吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 11573|回复: 254
收起左侧

[原创工具] 发票批量打印

    [复制链接]
th4c3y 发表于 2025-1-8 15:39
本帖最后由 th4c3y 于 2025-2-12 09:31 编辑

发票批量打印工具
2月12日更新:

更新内容:
1、纸张大小新增A5四版和A5两版(A5进纸方向为竖向)
2、增加打印预览功能(有个小bug,部分自定义纸张预览图与实际打印效果会不一致)
3、可选OFD格式打印(下载Spire.Pdf.dll,不下载则pdf和图片格式仍然可以正常打印)(单个OFD文件页面不超过3页)。
4、增加多版打印图片之间的间隙。
5、评论区反馈部分pdf打印机出现卡死,经测试是因为这些打印机调用了windows文件对话框保存pdf文件,由于软件使用了多线程,在打印子线程中调用模态对话框就会出现线程冲突,现修复Adobe PDF和Microsoft Print to PDF打印机出现的冲突;
其他打印机解决方式1:点击界面最下方:使用系统打印对话框进行打印 。
方式2:找到该打印机设置界面-打印机首选项-设置指定保存位置不弹出对话框(如果有)。
方式3:从打印预览界面进行打印。
方式4:更换虚拟打印机(论坛搜索的几款都还不错)。
6、应评论区需求增加同一发票打印两版在一张A4纸上的功能,使用方法:勾选‘复制页面*2’,设置纸张大小‘A4两版’。
7、文件列表中可按Delete键删减选中。
重复一遍:如果使用虚拟打印机推荐勾选合并页面(生成一个文件)。






1月16日更新:
可选A4三版 和自定义纸张大小打印
自定义纸张大小最多保留3个,超过3个最后添加的会覆盖最先添加的





1月12日更新:
可选A4 四版  和  A4 六版 打印
可选添加裁剪线








PDF/图片打印
文件路径传入方式:拖入文件或者文件夹,双击列表输入路径等。
虚拟打印机推荐合并页面(生成一个文件),否则不合并页面(打印机响应速度会快那么一点)
A5进纸方向为竖向:148mmX210mm(宽X高)
请先少量测试页面方向是否正确,设置是否生效,再批量打印。
64位,不支持win7
蓝奏:https://wwvv.lanzout.com/b00l1hq06d 密码:52pj

界面

界面

免费评分

参与人数 54吾爱币 +53 热心值 +47 收起 理由
蛋挞和挞皮 + 1 + 1 谢谢@Thanks!
guangcz + 1 + 1 谢谢@Thanks!
kuwangyilin + 1 + 1 谢谢@Thanks!
lxcbig + 1 谢谢@Thanks!
心随风 + 1 谢谢@Thanks!
sdr123 + 1 + 1 我很赞同!
zhxhwyzh14 + 1 我很赞同!
xyz1125 + 1 我很赞同!
XYWL0633 + 1 + 1 鼓励转贴优秀软件安全工具和文档!
KeyKeyKiYoMi + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
dzwindys + 1 + 1 谢谢@Thanks!
yuduopiaopiao + 1 + 1 谢谢@Thanks!
huangyijun833 + 1 + 1 谢谢@Thanks!
银狼锅 + 1 谢谢@Thanks!
simple91 + 1 + 1 谢谢@Thanks!
longpx + 1 谢谢@Thanks!
cooliceman20 + 1 谢谢@Thanks!
a5144 + 1 + 1 谢谢@Thanks!
waiter0201 + 1 + 1 我很赞同!
碎碎念的k + 1 + 1 谢谢@Thanks!
770229789 + 1 + 1 谢谢@Thanks!
koogg + 2 + 1 我很赞同!
dyy1314 + 1 + 1 谢谢@Thanks!
daiguixu + 1 + 1 好用好用!!!
梦想家C + 2 + 1 好东西,希望做个预览效果
FreeMagnet + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
daixiangjiang + 1 + 1 我很赞同!
zhbzhboy + 1 + 1 我很赞同!
surfzhang + 1 我很赞同!
KingHPP + 1 我很赞同!
a727014352 + 1 + 1 --------支持,刚好有个需求,打印一张纸又浪费了。
cocolingling123 + 1 + 1 谢谢@Thanks!
追逐飞翔 + 1 谢谢@Thanks!
LLCgcx + 1 + 1 我很赞同!
stcoolboy + 1 + 1 我很赞同!
a132926 + 1 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
yyp6457024 + 1 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
ranran2023 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
guangdao321 + 1 + 1 很好用,很实用
jalonewy + 1 + 1 鼓励转贴优秀软件安全工具和文档!
ljj-52pojie + 1 我很赞同!
yaoaijj511 + 1 + 1 热心回复!
WesleyChadMeod + 1 谢谢@Thanks!
stanly0805 + 1 + 1 谢谢@Thanks!
maweiwuai + 1 + 1 谢谢@Thanks!如果可以自定义尺寸就好了
xiaohang621 + 1 谢谢@Thanks!
虚生之忧 + 1 + 1 能不能增加A4三版啊?
wyt + 1 + 1 谢谢@Thanks!
gqdsc + 1 + 1 谢谢@Thanks!
ms2019 + 1 + 1 谢谢@Thanks!
zhujfxx + 1 + 1 我很赞同!
浩秦 + 1 + 1 谢谢@Thanks!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
Anro + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

浩秦 发表于 2025-1-9 16:35
[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
import sys
import os
import time
import fitz
from print import Ui_PrintForm
from itertools import count
from pathlib import Path
import configparser
from PIL.ImageQt import ImageQt
from PIL import Image
from PySide6.QtGui import QPainter, QPageSize, QPageLayout, QColor
from PySide6.QtPrintSupport import QPrinter, QPrintDialog, QPrinterInfo
from PySide6.QtCore import QRect, QObject, QThread, Signal, QEvent, Qt
from PySide6.QtWidgets import QApplication, QWidget, QListWidgetItem, QFileDialog, QStyleFactory
 
class printPdfWorker(QObject):
    finished = Signal()
    progress = Signal(str, str)
 
    def __init__(self, pdf=None, parent=None):
        super().__init__()
        self.win = parent
        self.paths = pdf
        self.cup = self.win.cup
        self.paper = self.win.paper
        self.printname = self.win.printName
        self.dpi = int(str(self.win.dpi)[:3])
        self.orientation = self.win.dirtion()
        ali = self.win.ali
        if '水平居中' in ali:
            self.inter = 2
        else# inserted
            if '靠右居中' in ali:
                self.inter = 1
        self.double = self.win.double
        self._printer = QPrinter(QPrinter.PrinterMode.HighResolution)
        self._printer.setPrinterName(self.printname)
        if 'A4' in self.paper:
            self._printer.setPageSize(QPageSize(QPageSize.A4))
            self.height_dpx, self.width_dpx = self.a4_size(self.dpi, 210, 297)
        else# inserted
            if 'A5' in self.paper:
                self._printer.setPageSize(QPageSize(QPageSize.A5))
                self.height_dpx, self.width_dpx = self.a4_size(self.dpi, 148, 210)
        self._printer.setPrintRange(QPrinter.PrintRange.AllPages)
        if self.win.checkbox.isChecked():
            self._printer.setColorMode(QPrinter.ColorMode.GrayScale)
        else# inserted
            self._printer.setColorMode(QPrinter.ColorMode.Color)
        try:
            self._printer.setDuplex(self.double)
        except Exception as e:
            pass  # postinserted
        else# inserted
            if self.orientation:
                self._printer.setPageOrientation(self.orientation)
        self._printer.setCopyCount(self.cup)
            print(e)
 
    def setprinton(self):
        if 'A4' in self.paper:
            self._printer.setPageSize(QPageSize(QPageSize.A4))
            self.height_dpx, self.width_dpx = self.a4_size(self.dpi, 210, 297)
        else# inserted
            if 'A5' in self.paper:
                self._printer.setPageSize(QPageSize(QPageSize.A5))
                self.height_dpx, self.width_dpx = self.a4_size(self.dpi, 148, 210)
        self._printer.setPrintRange(QPrinter.PrintRange.AllPages)
        if self.win.checkbox.isChecked():
            self._printer.setColorMode(QPrinter.ColorMode.GrayScale)
        else# inserted
            self._printer.setColorMode(QPrinter.ColorMode.Color)
        try:
            self._printer.setDuplex(self.double)
        except Exception as e:
            pass  # postinserted
        else# inserted
            if self.orientation:
                self._printer.setPageOrientation(self.orientation)
        self._printer.setCopyCount(self.cup)
            print(e)
        else# inserted
            pass
 
    def rundialog(self):
        self.dialog = QPrintDialog(self._printer)
        self.dialog.setOptions(QPrintDialog.PrintToFile | QPrintDialog.PrintSelection)
        if self.dialog.exec():
            self.runprint()
        else# inserted
            self.finished.emit()
 
    def runprint(self):
        """长时间运行的打印任务。"""  # inserted
        try:
            self.setprinton()
            if self.paper!= 'A4两版':
                if self.win.mergebox.isChecked():
                    painter = QPainter(self._printer)
                    rect = painter.viewport()
                    images = self.add_image(self.paths)
                    for pil_image, pageNumber in zip(images, count(1)):
                        if pageNumber > 1:
                            self._printer.newPage()
                        self.print_image(pil_image, rect, painter)
                    painter.end()
                else# inserted
                    for index, path in enumerate(self.paths):
                        painter = QPainter(self._printer)
                        rect = painter.viewport()
                        images = []
                        path = Path(path)
                        suffix = path.suffix.lower()
                        if suffix == '.pdf':
                            images = self.open_pdf(path, images)
                            for pil_image, pageNumber in zip(images, count(1)):
                                if pageNumber > 1:
                                    self._printer.newPage()
                                self.print_image(pil_image, rect, painter)
                        else# inserted
                            with Image.open(path) as image:
                                pass  # postinserted
        except Exception as e:
                                pil_image = image.copy()
                                self.print_image(pil_image, rect, painter)
                        painter.end()
            else# inserted
                if self.win.mergebox.isChecked():
                    images = self.add_image(self.paths)
                    self.A4_sep(images)
                else# inserted
                    batch_size = 10
                    for i in range(0, len(self.paths), batch_size):
                        batch_paths = self.paths[i:i + batch_size]
                        images = self.add_image(batch_paths)
                        self.A4_sep(images)
            self.progress.emit('文件已发送至打印机', 'green')
        else# inserted
            self.finished.emit()
                print(f'打印出错{e}0')
 
    def open_pdf(self, path, images):
        with fitz.open(path) as pdf:
            num_pages = len(pdf)
            printRange = range(num_pages)
            page_indices = [i for i in printRange]
            for index in page_indices:
                pixmap = pdf[index].get_pixmap(dpi=self.dpi)
                pil_image = Image.frombytes('RGB', [pixmap.width, pixmap.height], pixmap.samples)
                images.append(pil_image)
            return images
 
    def add_image(self, paths=None):
        images = []
        file_paths = paths
        file_paths = [path for path in file_paths if path.endswith('.pdf')] + [path for path in file_paths if path.endswith(('.jpg', '.jpeg', '.png'))]
        for index, path in enumerate(file_paths):
            path = Path(path)
            suffix = path.suffix.lower()
            if suffix == '.pdf':
                images = self.open_pdf(path, images)
            else# inserted
                with Image.open(path) as image:
                    images.append(image.copy())
        return images
 
    def A4_sep(self, images):
        if len(images) % 2!= 0:
            images.append(None)
        painter = QPainter(self._printer)
        for index, pageNumber in zip(range(0, len(images), 2), count(1)):
            image1 = images[index]
            image2 = images[index + 1]
            if pageNumber > 1:
                self._printer.newPage()
            self.join_pic(image1, image2, painter)
        painter.end()
 
    def print_image(self, pil_image, rect, painter):
        pilWidth, pilHeight = pil_image.size
        imageRatio = pilHeight / pilWidth
        viewportRatio = rect.height() / rect.width()
        A4Ratio = self.height_dpx / self.width_dpx
        if self.win.up == '自动旋转':
            if viewportRatio < 1 and imageRatio > 1 or (viewportRatio > 1 and imageRatio < 1):
                pil_image = pil_image.transpose(Image.ROTATE_90)
                pilWidth, pilHeight = pil_image.size
                imageRatio = pilHeight / pilWidth
            if A4Ratio < imageRatio:
                x = int(pilHeight / viewportRatio - pilWidth)
                xOffset = int(x / 2)
                yOffset = 0
            else# inserted
                xOffset = 0
                y = int(rect.height() - rect.width() / pilWidth * pilHeight)
                yOffset = int(y / self.inter)
        else# inserted
            xOffset, yOffset, x, y = (0, 0, 0, 0)
        if viewportRatio > imageRatio:
            y = int(rect.width() / (pilWidth / pilHeight))
            printArea = QRect(xOffset, yOffset, rect.width(), y)
        else# inserted
            x = int(pilWidth / pilHeight * rect.height())
            printArea = QRect(xOffset, yOffset, x, rect.height())
        image = ImageQt(pil_image)
        painter.drawImage(printArea, image)
        return painter
 
    def join_pic(self, image1, image2, painter):
        if image2 == None:
            image2 = Image.new('RGB', image1.size, 'white')
        for image in (image1, image2):
            pilWidth, pilHeight = image.size
            imageRatio = pilHeight / pilWidth
            if imageRatio > 1:
                if image == image1:
                    image1 = image.transpose(Image.ROTATE_90)
                if image == image2:
                    image2 = image.transpose(Image.ROTATE_90)
 
        def resize_image(image):
            height = int(self.height_dpx / 2)
            ratio = height / image.size[1]
            max_width = int(image.size[0] * ratio)
            max_height = int(height)
            if max_width > self.width_dpx:
                max_width = self.width_dpx
                ratio = self.width_dpx / image.size[0]
                max_height = int(image.size[1] * ratio)
            new_width = max_width
            new_height = max_height
            resized_image = image.resize((new_width, new_height))
            return resized_image
        image1 = resize_image(image1)
        image2 = resize_image(image2)
        half_hight = int(self.height_dpx / 2)
        merged_image = Image.new('RGB', (self.width_dpx, self.height_dpx), 'white')
        if image1.size[0] < self.width_dpx:
            x1 = int((self.width_dpx - image1.size[0]) / self.inter)
        else# inserted
            x1 = 0
        if image1.size[1] < half_hight:
            y1 = int((half_hight - image1.size[1]) / 2)
        else# inserted
            y1 = 0
        if image2.size[0] < self.width_dpx:
            x2 = int((self.width_dpx - image2.size[0]) / self.inter)
        else# inserted
            x2 = 0
        if image2.size[1] < half_hight:
            y2 = int((half_hight - image2.size[1]) / 2)
        else# inserted
            y2 = 0
        merged_image.paste(image1, (x1, y1))
        merged_image.paste(image2, (x2, half_hight + y2))
        rect = painter.viewport()
        self.print_image(merged_image, rect, painter)
 
    def a4_size(self, dpi, width, height):
        a4_width = width / 25.4
        a4_height = height / 25.4
        height_dpx = int(a4_height * dpi)
        width_dpx = int(a4_width * dpi)
        return (height_dpx, width_dpx)
 
class Window(QWidget):
    def __init__(self):
        super(Window, self).__init__()
        self.ui = Ui_PrintForm()
        self.ui_win = self.windowFlags()
        self.ui.setupUi(self)
        self.longRunningBtn = self.ui.pushButton
        self.longRunningBtn.clicked.connect(self.runPrintTask)
        self.addfile = self.ui.pushButton_2
        self.addfile.clicked.connect(self.getFile)
        self.clearfile = self.ui.pushButton_3
        self.clearfile.clicked.connect(self.clearFile)
        self.sysPrint = self.ui.toolButton
        self.sysPrint.clicked.connect(self.rundio)
        self.spinbox = self.ui.doubleSpinBox
        self.paper_box = self.ui.comboBox
        self.dpi_box = self.ui.comboBox_2
        self.double_box = self.ui.comboBox_3
        self.alignment = self.ui.comboBox_4
        self.direction = self.ui.comboBox_6
        self.paper_box.currentIndexChanged.connect(self.setdirection)
        self.bar = self.ui.label_8
        self.listwidget = self.ui.listWidget
        self.checkbox = self.ui.checkBox
        self.mergebox = self.ui.checkBox_2
        self.printbox = self.ui.comboBox_5
        self.load_printers()
        self.small_win = self.ui.dockWidget
        self.small_win.hide()
        self.textbox = self.ui.textEdit
        self.textbox.textChanged.connect(self.changedText)
        self.load_config()
        self.setdirection()
        self.file_path = []
        self.listwidget.viewport().installEventFilter(self)
 
    def eventFilter(self, source, event):
        if event.type() == QEvent.MouseButtonDblClick and source is self.listwidget.viewport():
            self.small_win.show()
            return True
        return super().eventFilter(source, event)
 
    def setdirection(self):
        if self.paper_box.currentText()!= 'A4':
            self.direction.setCurrentIndex(0)
            self.direction.setEnabled(False)
        else# inserted
            self.direction.setEnabled(True)
 
    def changedText(self):
        self.clearFile()
        text = self.textbox.toPlainText()
        lines = text.splitlines()
        for line in lines:
            if line.strip():
                self.showListwidget(line)
 
    def load_config(self):
        config = configparser.ConfigParser()
        config.read('printConfig.ini')
        self.spinbox.setValue(int(config.get('Print', 'Series', fallback=1)))
        self.paper_box.setCurrentIndex(int(config.get('Print', 'Paper', fallback=0)))
        self.dpi_box.setCurrentIndex(int(config.get('Print', 'Dpi', fallback=1)))
        self.double_box.setCurrentIndex(int(config.get('Print', 'Double', fallback=0)))
        self.double_box.setCurrentIndex(int(config.get('Print', 'Center', fallback=0)))
        self.printbox.setCurrentText(config.get('Print', 'PrintName', fallback=''))
        self.direction.setCurrentIndex(int(config.get('Print', 'PageDirection', fallback=0)))
        self.checkbox.setCheckState(Qt.CheckState.Checked if config.getboolean('Print', 'Color', fallback=False) else Qt.CheckState.Unchecked)
        self.mergebox.setCheckState(Qt.CheckState.Checked if config.getboolean('Print', 'Mergebox', fallback=False) else Qt.CheckState.Unchecked)
 
    def doublePrint(self):
        double = self.double_box.currentIndex()
        if double == 0:
            return QPrinter.DuplexMode.DuplexNone
        if double == 1:
            return QPrinter.DuplexLongSide
        if double == 2:
            return QPrinter.DuplexShortSide
        if double == 3:
            return QPrinter.DuplexAuto
 
    def dirtion(self):
        self.up = self.direction.currentText()
        if self.up == '纵向':
            return QPageLayout.Portrait
        if self.up == '横向':
            return QPageLayout.Landscape
 
    def clearFile(self):
        self.file_path = []
        self.listwidget.clear()
        self.runBar('准备就绪......', 'black')
 
    def getFile(self):
        response = QFileDialog.getOpenFileNames(parent=self, caption='选择文件', filter='文件类型 (*.pdf *.jpg *.png *.jpeg *.bmp);;Images (*.png *.jpg *.jpeg *.bmp);;PDF Files (*.pdf)')
        if response:
            file_paths = response[0]
            for path in file_paths:
                self.showListwidget(path)
 
    def showListwidget(self, path):
        self.file_path.append(path)
        item_widget = QListWidgetItem(path)
        self.listwidget.addItem(item_widget)
        self.bar.setText(f'已添加文件:{len(self.file_path)}个')
        return self.file_path
 
    def lianjie(self, paths):
        self.clearFile()
        valid_extensions = {'.jpg', '.png', '.jpeg', 'bmp', '.pdf'}
        for path in paths:
            _, extensions = os.path.splitext(path)
            if extensions.lower() in valid_extensions:
                self.showListwidget(path)
 
    def load_printers(self):
        printers = QPrinterInfo.availablePrinters()
        printer_names = [printer.printerName() for printer in printers]
        self.printbox.addItems(printer_names)
 
    def printdata(self):
        self.cup = self.spinbox.value()
        self.paper = self.paper_box.currentText()
        self.dpi = self.dpi_box.currentText()
        self.ali = self.alignment.currentText()
        self.double = self.doublePrint()
        self.printName = self.printbox.currentText()
        self.runBar('正在发送页面到打印机\n请勿关闭程序...', 'red')
 
    def rundio(self):
        pdf_file = self.file_path
        if not pdf_file:
            self.runBar('没有待打印的文件', 'blue')
            return
        self.printdata()
        self.thread = QThread()
        self.worker = printPdfWorker(pdf_file, self)
        self.worker.moveToThread(self.thread)
        self.thread.started.connect(self.worker.rundialog)
        self.worker.finished.connect(self.thread.quit)
        self.worker.finished.connect(self.worker.deleteLater)
        self.worker.progress.connect(self.runBar)
        self.thread.start()
 
    def runPrintTask(self):
        pdf_file = self.file_path
        if not pdf_file:
            self.runBar('没有待打印的文件', 'blue')
            return
        self.printdata()
        self.thread = QThread()
        self.worker = printPdfWorker(pdf_file, self)
        self.worker.moveToThread(self.thread)
        self.thread.started.connect(self.worker.runprint)
        self.worker.finished.connect(self.thread.quit)
        self.worker.finished.connect(self.worker.deleteLater)
        self.worker.progress.connect(self.runBar)
        self.thread.start()
 
    def runBar(self, text, color='black'):
        palette = self.bar.palette()
        palette.setColor(self.bar.foregroundRole(), QColor(color))
        self.bar.setPalette(palette)
        self.bar.setText(text)
 
    def dragEnterEvent(self, event):
        if event.mimeData().hasUrls():
            event.accept()
        else# inserted
            event.ignore()
 
    def dropEvent(self, event):
        valid_extensions = {'.jpg', '.png', '.jpeg', 'bmp', '.pdf'}
        dropped_files = []
        for url in event.mimeData().urls():
            file_path = url.toLocalFile()
            if os.path.isdir(file_path):
                for root, dirs, files in os.walk(file_path):
                    for file in files:
                        full_file_path = os.path.join(root, file)
                        _, extension = os.path.splitext(full_file_path)
                        if extension.lower() in valid_extensions:
                            dropped_files.append(full_file_path)
            else# inserted
                _, extension = os.path.splitext(file_path)
                if extension.lower() in valid_extensions:
                    dropped_files.append(file_path)
        for file_path in dropped_files:
            self.showListwidget(file_path)
 
    def closeEvent(self, event):
        self.save_combobox()
        event.accept()
 
    def save_combobox(self):
        config = configparser.ConfigParser()
        config.read('printConfig.ini')
        if 'Print' not in config:
            config.add_section('Print')
        cup = self.spinbox.value()
        paper = self.paper_box.currentIndex()
        dpi = self.dpi_box.currentIndex()
        double = self.double_box.currentIndex()
        center = self.alignment.currentIndex()
        printName = self.printbox.currentText()
        direction = self.direction.currentIndex()
        mergebox = int(self.mergebox.checkState() == Qt.CheckState.Checked)
        config['Print'] = {'Series': int(cup), 'Paper': str(paper), 'Dpi': str(dpi), 'Double': str(double), 'Center': str(center), 'Color': str(int(self.checkbox.checkState() == Qt.CheckState.Checked)), 'PrintName': str(printName), 'PageDirection': str(direction), 'Mergebox': str(mergebox)}
        with open('printConfig.ini', 'w') as configfile:
            config.write(configfile)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    app.setStyle(QStyleFactory.create('Fusion'))
    win = Window()
    win.show()
    sys.exit(app.exec())
 楼主| th4c3y 发表于 2025-1-15 20:13
zhujfxx 发表于 2025-1-15 11:31
期待 老板继续优化下
A4两版时候 上下部分 向上下两端再缩进些

你的需求版本已经上传了网盘了,打印居中方式选择‘’垂直两端‘’
jun269 发表于 2025-1-8 15:54
zyx665121 发表于 2025-1-8 16:07
2张发票合并页面打印,并不是选择合并页面,而是纸张大小选A4两版。还有2个问题,能不能自由删除添加进去序列的文件,和输出PDF版自己保存。
ww5270616 发表于 2025-1-8 16:09
感谢,这个是神级需求啊,谢谢
leishe2023 发表于 2025-1-8 16:31
有空用一下谢谢分享
milygy 发表于 2025-1-8 16:44
省时省力,感谢
zky1608 发表于 2025-1-9 13:28
非常好,谢谢,收藏了
zhujfxx 发表于 2025-1-9 13:54
实测 A4两版 从中间裁剪后 上下俩部分 过大
提个意见
A4两版 时候,上下部分分别 向上和向下靠齐 也就是两端缩进些
中间区域留白增加
会更好
银枫月影 发表于 2025-1-9 17:14
这个一定要顶
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-21 01:26

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表