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}")
相关推荐
百事牛科技7 小时前
两种方法锁定 PDF,拒绝内容被随意篡改
windows·pdf
HappyAcmen10 小时前
1.pdfplumber安装,PDF文字提取
python·pdf
开开心心_Every12 小时前
多连接方式的屏幕共享工具推荐
运维·服务器·pdf·电脑·excel·tornado·dash
HappyAcmen14 小时前
2.PDF长文档完整读取
python·pdf·rag
慈云数据14 小时前
【免费开源】多格式文件转换工具 Pro:图片、PDF、文档、批量重命名一站式转换
pdf
2601_961194021 天前
2026六级词汇PDF下载|大学英语六级单词表+音频PDF
windows·git·eclipse·pdf·github
蜡台2 天前
Uniapp 实现预览pdf 文件
pdf·uni-app·pdfh5
AI英德西牛仔2 天前
Claude 导出 pdf 颜色不一样怎么办,选用 AI 导出鸭优化格式转换,多维度落地修正 PDF 色彩失真问题
javascript·人工智能·ai·chatgpt·pdf·deepseek·ai导出鸭
南风微微吹2 天前
【专四】英语专业四级历年真题试卷及答案解析电子版PDF(2009-2025年)
pdf
SunnyDays10112 天前
Java 实现 PDF 转 PDF/A 和 PDF/A 转 PDF(超详细教程)
java·开发语言·pdf