树莓派打印机配置

参考连接:https://www.techradar.com/in/how-to/computing/how-to-turn-the-raspberry-pi-into-a-wireless-printer-server-1312717/2

想代码控制打印首先 install python-cups which allows python programs to print to the CUPS server:
sudo apt-get install python-cups
在这里插入图片描述

using the printer drivers. You can also use Python to generate printer-friendly content.
This is best done by using the PyCups library, which provides Python bindings for the CUPS server. Install the library with:

$ sudo apt-get install python-cups

Then create an example.py Python script with:

import cups
conn = cups.Connection()
printers = conn.getPrinters ()
for printer in printers:
print printer, printers[printer][“device-uri”]

The script fetches details about all the printers managed by CUPS and prints their name and device address to the screen. When you execute the script, it produces an output similar to the following:

EPSON_LX-300 usb://EPSON/LX-300+?serial=L010209081
RICOH_Aficio_SP_100 usb://RICOH/
Aficio?serial=T382M977983

You can also print files from the Python script using the printFile function, by specifying them in the format:

$ printFile (name of the printer, filename to print, job title,
options)

Open the previous example.py script and add the following lines to it:

file = “/home/pi/testfile.txt”
printer_name=printers.keys()[0]
conn.printFile (printer_name, file, “Project Report”, {})

The first line saves the name of the file you wish to print inside a variable named file. The second line fetches the list of printers and saves the first name, which is the default printer inside a variable named printer_name. The third line then uses the first two variables and prints the file in the specified format.

参考连接:https://www.cnblogs.com/zhuchengchao/p/11619790.html
前言:
在树莓派端,通过USB口连接打印机,对打印机进行配置,控制打印机的打印和扫描功能。
一、打印配置
配置流程
1.驱动确定
由于确定使用HP家的打印机,因此进入HP的官网:

https://developers.hp.com/hp-linux-imaging-and-printing/supported_devices/index

查询打印机是否支持Linux的驱动

2.驱动安装
进入树莓派控制窗口,运行以下命令:
sudo apt-get install hplip

再运行命令,将pi用户 加入到 lpadmin:
sudo usermod -a -G lpadmin pi

成功之后安装hplip-gui,通过以下命令:
sudo apt-get install hplip-gui

安装成功后进行如下步骤:

在终端输入hp-setup

在弹出的窗口中选择Universal Serial Bus(USB)—>next

选择打印机,此处我的打印机为HP LaserJet MFP m227-m231选择它—>next

注:若无打印机,则插拔一下打印机的USB线

在下一界面中,勾选Printer Setup—>Add Printer

Fax Setup为传真机功能,可不勾选

会弹出输入用户名和密码的框,输入即可

至此打印机已经配置成功了

选择默认的打印机,我是通过菜单栏->Preference->HPLIP Toolbox->Printer Control里选择打印机为默认的打印机Set as Default

若未设置成功,重启一下再设置即
使用流程
lsusb:查看连接的USB设备

CUPS(common unix printing standard)安装和使用:
参考连接:https://rohankapoor.com/2012/06/configuring-the-raspberry-pi-as-an-airprint-server/

软件包 CUPS 就是为共享打印机而生。我们要做的只是将打印机用 USB 线缆连接树莓派,然后安装并配置 CUPS。
安装命令:
sudo apt-get install cups

Raspbian 系统会自动安装相关依赖,包括打印机驱动。安装完成后,需要将用户加入到 lpadmin 用户组,然后开启 CUPS 的远程访问权限:
sudo usermod -aG lpadmin pi
sudo cupsctl --remote-any

打开配置文件:
sudo nano /etc/cups/cupsd.conf
找到Listen localhost:631,并将其备注,然后增加Port 631
只要它指向端口631,CUPS在任何网络接口上监听任何信息。
在这里插入图片描述
We also need to tell CUPS to alias itself to any hostname as AirPrint communicates with CUPS with a different hostname than the machine-defined one. To do this we need to add the directive ServerAlias * before the first block.
在这里插入图片描述

三处 Location段落中添加“allow @local”行after the line Order allow, deny – however this does not apply to all instances of that line.
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
修改好之后运行下面的命令,重启Cups
sudo /etc/init.d/cups restart
重新启动CUPS后,您能够通过将Web浏览器指向本地网络上的任何计算机访问管理面板:http:// [Pi的IP或主机名]:631

关闭服务:
sudo service cups stop
打开服务:
sudo service cups start

lpstat
-a # 显示打印机的接受状态。
-c # 显示打印类。
-p # 显示打印状态:已启用或已禁用。
-s # 显示默认的一个或多个打印机和类。等效于 -d、 -c 和 -v。请注意,必须将多个选项隔开,因为可为许多选项指定值。
-s # 显示打印机及其设备。

lp:打印命令(可以通过man lp查看)
lp -d 指定打印机(若已经设置了默认打印机,则不需要指定) 文件名
lp ./Desktop/test.jpg

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值