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}")
相关推荐
南风微微吹25 分钟前
英语四级作文历年真题及范文模版汇总PDF电子版(2015-2025年6月)
pdf·英语四级
TextIn智能文档云平台4 小时前
如何快速提取PDF文档内容
pdf
小马爱打代码5 小时前
Spring AI:DeepSeek 整合 RAG 增强检索: 实现与 PDF 对话
人工智能·spring·pdf
南风微微吹5 小时前
英语六级作文历年真题及范文模版汇总PDF电子版(2015-2025年6月)
pdf·英语六级
verse_armour6 小时前
markdown插入文献引用并导出pdf
pdf·markdown·pandoc·latex
月屯7 小时前
pandoc安装与使用(html、makdown转docx、pdf)
前端·pdf·html·pandoc·转docx、pdf
星空椰1 天前
Java Excel转PDF
pdf·excel
Charlene Fung1 天前
如何使用 Markdown 生成带参考文献的 PDF
论文阅读·pdf·markdown
std860211 天前
微软发布 Edge 143 稳定版:PDF 注释支持撤销重做
microsoft·edge·pdf
shadowcz0071 天前
关于GEO的研究总结#使用 Notebooklm 来研究论文和整理报告#PDF分享
人工智能·pdf