python 调用SumatraPDF 静默打印PDF

复制代码
SumatraPDF 文档
https://www.sumatrapdfreader.org/docs/Command-line-arguments
⽆边框 noscale/缩⼩到合适⼤⼩(默认)shrink/合适⼤⼩ fit/compat 兼容
# 分为 Portrait (纵向)和 Landscape (横向)两类
https://github.com/sumatrapdfreader/sumatrapdf
复制代码
def SumatraPDF():
    from pypdf import PdfReader
    import subprocess
    bit_number = platform.architecture()[0] # 判断电脑是32位还是64位
    if bit_number == '64bit':# 不用安装
        other_printer = './SumatraPDF64.exe'
    else:
        other_printer = './SumatraPDF32.exe'
    pdf_file1 = './81160747558912_1.pdf'
    cprinter = 'xxxx'  # 打印机名称
    # 判断打印方向
    reader = PdfReader(pdf_file1)
    page0 = reader.pages[0]
    width = page0.mediabox.width
    height = page0.mediabox.height
    if int(width) > int(height):
        scale = 'portrait'
    elif int(width) < int(height) == 842:
        scale = 'landscape'
    else:
        scale = 'portrait'
    # "fit,{scale},1-,paperkind=258,1x"
    #print-settings指定打印机参数,fit适合页面,scale 方向,1-从第一页到最后一页,lx 打印一份,2x打印2份
    args1 = [f"{other_printer}",
             "-silent", # 静默打印
             "-print-to", #指定下一行为打印机名称
             f'{cprinter}',
             "-print-settings", 
             f"fit,{scale},1-,paperkind=258,1x"
             "-exit-on-print", # 打印结束自动退出
             "-disable-auto-rotation", #禁止自动旋转
             f"{pdf_file1}" #PDF路径
             ]
    subprocess.run(args1, encoding="utf-8", shell=True)
    print(f"\t|已发送至打印机:{cprinter}")
相关推荐
shuaiqinke4 小时前
【分享】Master PDF Editor v5.9.98便携版 多功能PDF编辑工具
智能手机·pdf
jianwuhuang825 小时前
Kimi怎么导出pdf
人工智能·chatgpt·pdf·deepseek·ai导出鸭
daanpdf6 小时前
四六级翻译《中国文化概况》双语批注版pdf百度网盘
pdf
daanpdf7 小时前
古籍原文周易(易经)全文完整版PDF
pdf
daanpdf7 小时前
大学英语四级试卷历年真题及答案PDF电子版百度网盘
pdf
hikktn7 小时前
Excel模板智能转PDF:零硬编码的通用打印解决方案
windows·pdf
m0_502724957 小时前
vue3生成pdf
前端·javascript·vue.js·pdf
驯龙高手_追风1 天前
Adobe Acrobat PDF阅读器设置默认滚动翻页
adobe·pdf·adobe acrobat reader·adobe reader
优化控制仿真模型1 天前
【26年社工】初级社会工作者历年真题及答案PDF电子版(2010-2025年)
经验分享·pdf
ComPDFKit1 天前
PDF发票生成怎么做?从零到服务化落地的完整指南
pdf·pdf生成·文件生成·发票生成