栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

python 全自动打印网站

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

python 全自动打印网站

python 全自动打印网站
  • 项目介绍
  • 开始部署项目
    • 导入pywin32,os,flask库
    • 源代码
    • 花生壳内网穿透
    • 创建一个保存打印文件的目录
    • 运行项目
  • 说明
    • 打印机高级选项设置

项目介绍
  • win32print可以打开打印机,进行打印操作,以及一些高级打印机设置。
  • flask作为一个轻量级的web框架,很适合做一个无人打印自助的前端技术。
  • 使用花生壳进行内网穿透
  • 界面使用bootstrap稍加美化
  • 可以实现远程提交docx文件到本地电脑,调动打印机打印文件

    后端截图

    前端截图
开始部署项目 导入pywin32,os,flask库

源代码
#!/user/bin/python
# _*_ coding:utf-8 _*_
#开发人员:eu_zero
#开发时间2021/10/19 16:57
#文件名称: test.py
#开发工具: pycharm
#项目名称 test
from flask import Flask
from flask import request
import os
import win32print
import win32api

def printer_loading(filename,chooseDuplex,chooseColor,chooseCopies):
    # name = win32print.GetDefaultPrinter()
    name = "EPSON L3150 Series"

    # printdefaults = {"DesiredAccess": win32print.PRINTER_ACCESS_ADMINISTER}
    printdefaults = {"DesiredAccess": win32print.PRINTER_ACCESS_USE}
    handle = win32print.OpenPrinter(name, printdefaults)

    level = 2
    attributes = win32print.GetPrinter(handle, level)
    print("old Duplex = %d" % attributes['pDevMode'].Duplex)
    print("old Orientation = %d" % attributes['pDevMode'].Orientation)
    print("old color = %d" % attributes['pDevMode'].Color)
    print("old copies = %d" % attributes['pDevMode'].Copies)
    attributes['pDevMode'].Duplex = int(chooseDuplex)           # 1单面 2长边装订双面 3短边装订双面
    attributes['pDevMode'].Orientation = 2                       #纵向打印(暂时无法横向打印)
    attributes['pDevMode'].Color = int(chooseColor)             # 0彩色 1黑白
    attributes['pDevMode'].Copies = int(chooseCopies)           #份数
    try:
        win32print.SetPrinter(handle, level, attributes, 0)
    except:
        print("new Duplex = %d" % attributes['pDevMode'].Duplex)
        print("new Orientation = %d" % attributes['pDevMode'].Orientation)
        print("new color = %d" % attributes['pDevMode'].Color)
        print("new copies = %d" % attributes['pDevMode'].Copies)
    res = win32api.ShellExecute(0, 'print', filename, None, '.', 0)
    win32print.ClosePrinter(handle)

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def home():
    return '''



    
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/360294.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号