在麒麟操作系统上通过网页调用打印机进行打印

内容分享3天前发布
0 0 0

在麒麟操作系统上通过网页调用打印机进行打印,主要有以下几种方案:

一、CUPS 网页管理界面打印

1. 安装和配置 CUPS


# 安装 CUPS 和相关组件
sudo apt update
sudo apt install cups cups-client cups-bsd cups-filters

# 将用户添加到 lpadmin 组
sudo usermod -a -G lpadmin $USER

# 启动 CUPS 服务
sudo systemctl start cups
sudo systemctl enable cups

2. 访问 CUPS 网页接口

打开浏览器访问:
http://localhost:631

或通过网络访问:
http://<麒麟系统IP>:631

3. 通过 CUPS API 进行打印


<!-- 简单的打印表单 -->
<form action="http://localhost:631/printers/打印机名" 
      method="POST" 
      enctype="multipart/form-data">
    <input type="file" name="file">
    <input type="submit" value="打印">
</form>

二、使用 Web 打印服务方案

方案1:node-printer + Express(推荐)


// 安装依赖
npm install express printer node-print

// server.js
const express = require('express');
const {
   
    print } = require('node-print');
const fs = require('fs');

const app = express();

app.post('/print', (req, res) => {
   
   
    const filePath = '/tmp/print.pdf';
    const printerName = 'HP-LaserJet'; // 打印机名称
    
    // 使用 lp 命令打印
    const {
   
    exec } = require('child_process');
    exec(`lp -d ${
     
     printerName} ${
     
     
© 版权声明

相关文章

暂无评论

none
暂无评论...