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}")
相关推荐
汤姆百宝箱3 小时前
2026新版教材电子课本1-9年级新教材PDF(完整电子版下载)
pdf·小学课本·初中课本·电子教材·电子课本·2026新教材·2026新课本
开开心心就好3 小时前
内存清理软件灵活设置,自动阈值快捷键清
运维·服务器·windows·pdf·harmonyos·risc-v·1024程序员节
海兰3 小时前
【接上篇】多格式文档支持扩展方案(PDF_Word_Excel)
pdf·word·excel
鸿乃江边鸟4 小时前
用 oh-my-opencode 写一个word转pdf skill
pdf·大模型·opencode
软件资深者1 天前
2026 版初中几何辅助线教材 PDF|打印即提分,中考几何 “分水岭” 一键通关
学习·数学·pdf·教学·初中数学
Loo国昌1 天前
【AI应用开发实战】07_文档解析路由与质量评估:从传统PDF解析到Docling现代化方案
人工智能·后端·python·自然语言处理·pdf
开开心心就好1 天前
文字转语音无字数限,对接微软接口比付费爽
java·linux·开发语言·人工智能·pdf·语音识别
lpfasd1231 天前
适合Markdown转PDF的方案推荐
pdf
lpfasd1231 天前
PDF导出方案深度对比:性能、质量与适用场景分析
pdf·程序员创富
l1t1 天前
利用DeepSeek辅助把幻灯片markdown文件转换成pdf
人工智能·pdf