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_965912913 小时前
PDF转Word工具深度横评:2026年国内免费方案技术对比
pdf·word
2501_930707785 小时前
使用C#代码将PDF转化为线性PDF文件
pdf
诸葛大钢铁5 小时前
PDF无法复制文字怎么办?3种方法解除PDF复制限制并提取文字
pdf·ocr·pdf教程·pdf解除限制·pdf无法复制·pdf文字识别
2501_930707787 小时前
使用C#代码调整 PDF 版本
pdf
wtsolutions8 小时前
PDF-to-Image-PDF的安全优势 - 保护您的文档和数据
pdf
qq_366624788 小时前
在线PDF翻译工具在多语言技术文档处理中的实战应用
microsoft·pdf
肖恭伟9 小时前
MinerU 新手完整配置教程:Windows 下将 PDF 转为带图片的 Markdown
windows·pdf
开开心心_Every9 小时前
电脑文件搜索软件支持内容和拼音搜索
linux·服务器·人工智能·r语言·pdf·音视频·symfony
随手工具-Excel, pdf, SQL1 天前
多个 PDF 怎么合并成一个?免费在线工具,还能混入图片和 Word
pdf·word·效率工具·在线工具·pdf合并·合并pdf
2601_965912831 天前
PDF加水印工具实测:2026年国内免费方案对比
pdf