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}")
相关推荐
开开心心就好1 天前
安卓免费证件照制作软件,无广告弹窗
linux·运维·安全·pdf·迭代器模式·依赖倒置原则·1024程序员节
YXWik61 天前
Linux 环境 libreoffice 执行word转pdf 中文乱码问题
linux·pdf·word
这辈子谁会真的心疼你1 天前
怎么把caj转化为pdf?批量转换的方法
pdf
南风微微吹1 天前
【2026年最新】英语四级历年真题及答案解析PDF电子版(2015-2025年12月)
pdf·英语四级
其实秋天的枫1 天前
2025年12月大学英语六级真题及答案电子版pdf三套全
经验分享·pdf
优化控制仿真模型2 天前
2026年最新驾考科目一考试题库2309道全。电子版pdf
经验分享·算法·pdf
脑电信号要分类2 天前
将多张图片拼接成一个pdf文件输出
pdf·c#·apache
软件工程小施同学2 天前
区块链论文速读 CCF A--CCS 2025 (2) 附pdf下载
网络·pdf·区块链
你好1234567890122 天前
PDF编辑软件 pdfelement绿色版
pdf
月巴月巴白勺合鸟月半3 天前
一次PDF文件的处理(一)
pdf·c#