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}")
相关推荐
2601_9611940216 分钟前
27考研刘晓艳单词pdf
linux·sql·ubuntu·华为·pdf·.net
AI刀刀1 小时前
智谱清言保存 pdf 显示该页的尺寸超出范围,AI 导出鸭智能适配页面尺寸稳定导出 PDF
人工智能·pdf·ai导出鸭
GIS从业者3 小时前
免费的PDF工具PDF24工具箱
pdf
2601_961194026 小时前
专升本财务管理重点知识整理|2026财务管理真题计算题PDF电子版
pdf
俊哥工具8 小时前
电脑怎么玩手机APP?超简单新手教程
pdf·电脑·word·excel·音视频
时尚IT男9 小时前
Python发票识别实战:从PDF中精准提取发票号与(小写)¥金额
开发语言·python·pdf
划水的code搬运工小李10 小时前
下载CSDN到PDF
开发语言·pdf·swift
2601_9611940211 小时前
化学教资科三真题答案
linux·windows·ubuntu·pdf·centos·gnu
2601_9611940212 小时前
2026初级会计实务教材电子版|章节讲义+习题PDF
python·考研·django·pdf·virtualenv·pygame
2601_9611940212 小时前
考研政治历年真题及解析pdf
stm32·单片机·嵌入式硬件·物联网·考研·pdf