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}")
相关推荐
FinelyYang14 小时前
uniapp使用kkfileview在线预览ppt,excel,word,pdf类型文件
pdf·uni-app·powerpoint
WORLDPO92261 天前
QTE-020-01-L/F/C-D-A-K-TR_实物_数据手册PDF_国产替代
pdf
asdzx671 天前
C# 操作 PDF 元数据:从属性写入到字段提取的完整流程
前端·pdf·c#
WORLDPO92262 天前
SFSDT-10/15/20/25/35-28-G-19.69-SR_实物图_数据手册PDF_国产替代
pdf·pcb工艺·pcb
梦想出海-Phoebe2 天前
Gemini新增文件编辑功能:PDF、Word、Excel处理体验分享
pdf·word·excel
开开心心就好2 天前
网页图片批量下载工具,输入链接就保存
服务器·算法·leetcode·支持向量机·pdf·ocr·1024程序员节
汤姆宝库3 天前
法考历年真题及答案解析合集pdf版(2002-2025年)
pdf·法考
优化控制仿真模型3 天前
2026【英一】考研英语一历年真题及答案解析PDF电子版(1980-2025年)
考研·pdf
云月呀4 天前
《死亡回忆录》藏汉双语版电子版 PDF,穆迪博士 150 例濒死体验访谈,一部关于生死的温柔读本
pdf·死亡回忆录
xiaolinudao1234 天前
给pdf文件盖骑缝章的软件有哪些
pdf