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}")
相关推荐
AI导出鸭PC端18 分钟前
预览即导出:告别AI文档格式崩塌,网页预览效果1:1落地Word
人工智能·pdf·word·流程图·豆包·ai导出鸭
hu556679821 分钟前
小规模纳税人财务报表报送后如何导出报送pdf
pdf
__zRainy__34 分钟前
基于计数信号量(Counting Semaphore)的 PDF 渲染并发控制方案
pdf
工具派3 小时前
从 git commit 到交付 PDF:我的一条在线工具流实录
git·elasticsearch·pdf
Li Ming&17 小时前
Python办公自动化:利用Python批量将PDF转换为图片文件
python·pdf·pip
ji_shuke19 小时前
Vue3 前端批量打印 PDF/图片踩坑记:跨域、合并打印、对话框闪退与按钮一直 loading
前端·pdf·状态模式·pdf打印
Am-Chestnuts19 小时前
Mermaid流程图怎么导出Word/PDF?DS随心转批量保存AI多轮修改与源码
pdf·aigc·word·流程图
FL16238631291 天前
pdf批量转ofd本地离线操作简单支持win10及以上系统
pdf
Metaphor6921 天前
使用 Python 在 PDF 中插入、替换和删除图片
python·pdf
薛定猫AI1 天前
【技术干货】大模型文档结构化提取实战:Python解析PDF发票并批量生成CSV
java·python·pdf