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}")
相关推荐
阿伟玩不懂33 分钟前
AI帮你读PDF——自建文档解析与智能问答工具
人工智能·pdf
霸道流氓气质17 小时前
基于本地 PaddleOCR 的 PDF 文字识别完整技术文档
开发语言·r语言·pdf
2601_9659130017 小时前
多份PDF批量转Word合并,三次踩坑后的方案对比与性能评估
pdf·word
桐桐桐17 小时前
PDF 翻译工具横评与自建批量方案:从在线工具到 Python 自动化
python·pdf·自动化
百事牛科技19 小时前
办公文档防护:如何限制 PDF 转换成其他格式文件
windows·pdf
SunnyDays101119 小时前
Java 给 PDF 添加页码:实现“第 X 页,共 Y 页”
java·pdf·页码
2601_9659128320 小时前
520MB卷宗合并压缩踩坑实录:PDF文档归档场景的技术选型与性能对比
pdf
霸道流氓气质20 小时前
本地用 Ollama + 视觉模型识别 PDF 技术教程
pdf
经典19921 天前
解析pdf表格内容
windows·pdf
星花月1 天前
【无标题】
ai·语言模型·pdf·deep learning