首页 > 代码库 > [daily] linux添加打印机

[daily] linux添加打印机

只用过HP的打印机,用过两个,分别是:HP_p2055dn, 和 HP_LaserJet_Professional_M1216nfh  别的不知道。以下内容仅试用于HP打印机。

 

第一:装HP,打印机工具 

pacman -S hplip

这个包,自带配置工具和打印机驱动。

其实,装这个就能用了,然后使用自带工具hp-toolbox,hp-setup之类的一设置。

不过在几年前使用第一台打印机2055的时候,我还不太懂,所以学习了一个开放的打印机接入服务cups(到底是干啥的,我也并不太知道),cups支持所有主流的打印机。

所以我当时使用的cups来添加打印机。理论上你可以用cups来添加管理所有的打印机,但是非HP的,应该是需要另装驱动的,我不清楚。

第二:基于以上,安装cups

pacman -S cups

第三:启动cups服务:

>>> systemctl start org.cups.cupsd

第四:使用浏览器访问cups服务: http://localhost:631/

  在页面里可以找到添加打印机的向导,然后跑到打印机旁边,找到品牌,型号标签,然后记下来。使用socket://172.168.10.98/ 添加打印机。并选择品牌,然后选择对应型号的驱动。最后完成向导。

  然后,打印测试页。在job里查看是否成功。如果错了,80%是驱动选错了。重来该步骤,直到成功!

第五:理论上,在第四步骤里边,你就已经成功了。如果你来到了第五步,说明你没有成功。

  如果你的打印机不是HP,请关闭该页,去google重新search。然后,最终你一定成功,欢迎回来留言,分享经验 :)

  如果你的打印机是HP的,并且是m1216nfh,那么恭喜你和我的问题一样,请继续阅读。

  我遇到的问题:添加成功,打印失败,说:filter failed

  技术分享

  查看了详细日志文件 /var/log/cups/error_log

技术分享
W [11/Nov/2016:16:12:03 +0800] CreateProfile failed: org.freedesktop.ColorManager.AlreadyExists:profile id \hp-m1216nfh-Gray..\‘ already exists
W [11/Nov/2016:16:12:03 +0800] CreateProfile failed: org.freedesktop.ColorManager.AlreadyExists:profile id \hp-m1216nfh-RGB..\‘ already exists
E [11/Nov/2016:16:13:06 +0800] [Job 23] Job stopped due to filter errors; please consult the error_log file for details.
D [11/Nov/2016:16:13:06 +0800] [Job 23] The following messages were recorded from 04:13:05 PM to 04:13:06 PM
D [11/Nov/2016:16:13:06 +0800] [Job 23] Adding start banner page "none".
D [11/Nov/2016:16:13:06 +0800] [Job 23] Adding end banner page "none".
D [11/Nov/2016:16:13:06 +0800] [Job 23] File of type application/vnd.cups-pdf-banner queued by "root".
D [11/Nov/2016:16:13:06 +0800] [Job 23] hold_until=0
D [11/Nov/2016:16:13:06 +0800] [Job 23] Queued on "hp-m1216nfh" by "root".
D [11/Nov/2016:16:13:06 +0800] [Job 23] time-at-processing=1478851985
D [11/Nov/2016:16:13:06 +0800] [Job 23] 4 filters for job:
D [11/Nov/2016:16:13:06 +0800] [Job 23] bannertopdf (application/vnd.cups-pdf-banner to application/pdf, cost 32)
D [11/Nov/2016:16:13:06 +0800] [Job 23] pdftopdf (application/pdf to application/vnd.cups-pdf, cost 66)
D [11/Nov/2016:16:13:06 +0800] [Job 23] gstoraster (application/vnd.cups-pdf to application/vnd.cups-raster, cost 99)
D [11/Nov/2016:16:13:06 +0800] [Job 23] hpcups (application/vnd.cups-raster to printer/hp-m1216nfh, cost 0)
D [11/Nov/2016:16:13:06 +0800] [Job 23] job-sheets=none,none
D [11/Nov/2016:16:13:06 +0800] [Job 23] argv[0]="hp-m1216nfh"
D [11/Nov/2016:16:13:06 +0800] [Job 23] argv[1]="23"
D [11/Nov/2016:16:13:06 +0800] [Job 23] argv[2]="root"
D [11/Nov/2016:16:13:06 +0800] [Job 23] argv[3]="Test Page"
D [11/Nov/2016:16:13:06 +0800] [Job 23] argv[4]="1"
D [11/Nov/2016:16:13:06 +0800] [Job 23] argv[5]="job-uuid=urn:uuid:fb232c3c-f68d-3701-7b64-7f034da35129 job-originating-host-name=localhost date-time-at-creation= date-time-at-processing= time-at-creation=1478851985 time-at-processing=1478851985"
D [11/Nov/2016:16:13:06 +0800] [Job 23] argv[6]="/var/spool/cups/d00023-001"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[0]="CUPS_CACHEDIR=/var/cache/cups"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[1]="CUPS_DATADIR=/usr/share/cups"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[2]="CUPS_DOCROOT=/usr/share/cups/doc"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[3]="CUPS_FONTPATH=/usr/share/cups/fonts"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[4]="CUPS_REQUESTROOT=/var/spool/cups"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[5]="CUPS_SERVERBIN=/usr/lib/cups"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[6]="CUPS_SERVERROOT=/etc/cups"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[7]="CUPS_STATEDIR=/run/cups"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[8]="HOME=/var/spool/cups/tmp"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[9]="PATH=/usr/lib/cups/filter:/usr/bin:/usr/bin:/bin:/usr/bin"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[10]="SERVER_ADMIN=root@T7"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[11]="SOFTWARE=CUPS/2.2.1"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[12]="TMPDIR=/var/spool/cups/tmp"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[13]="USER=root"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[14]="CUPS_MAX_MESSAGE=2047"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[15]="CUPS_SERVER=/run/cups/cups.sock"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[16]="CUPS_ENCRYPTION=IfRequested"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[17]="IPP_PORT=631"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[18]="CHARSET=utf-8"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[19]="LANG=en_US.UTF-8"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[20]="PPD=/etc/cups/ppd/hp-m1216nfh.ppd"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[21]="RIP_MAX_CACHE=128m"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[22]="CONTENT_TYPE=application/vnd.cups-pdf-banner"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[23]="DEVICE_URI=socket://172.168.10.98"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[24]="PRINTER_INFO=HLYT-Printer-Black"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[25]="PRINTER_LOCATION=HLYT"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[26]="PRINTER=hp-m1216nfh"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[27]="PRINTER_STATE_REASONS=none"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[28]="CUPS_FILETYPE=document"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[29]="FINAL_CONTENT_TYPE=application/vnd.cups-raster"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[30]="AUTH_I****"
D [11/Nov/2016:16:13:06 +0800] [Job 23] Started filter /usr/lib/cups/filter/bannertopdf (PID 5878)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Started filter /usr/lib/cups/filter/pdftopdf (PID 5879)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Started filter /usr/lib/cups/filter/gstoraster (PID 5880)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Started filter /usr/lib/cups/filter/hpcups (PID 5881)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Started backend /usr/lib/cups/backend/socket (PID 5882)
D [11/Nov/2016:16:13:06 +0800] [Job 23] pdftopdf: Last filter determined by the PPD: hpcups; FINAL_CONTENT_TYPE: application/vnd.cups-raster => pdftopdf will not log pages in page_log.
D [11/Nov/2016:16:13:06 +0800] [Job 23] PDF template file doesn\t have form. It\‘s okay.
D [11/Nov/2016:16:13:06 +0800] [Job 23] OUTFORMAT=\"(null)\", so output format will be CUPS/PWG Raster
D [11/Nov/2016:16:13:06 +0800] [Job 23] PID 5878 (/usr/lib/cups/filter/bannertopdf) exited with no errors.
D [11/Nov/2016:16:13:06 +0800] [Job 23] STATE: +connecting-to-device
D [11/Nov/2016:16:13:06 +0800] [Job 23] Looking up \"172.168.10.98\"...
D [11/Nov/2016:16:13:06 +0800] [Job 23] PID 5879 (/usr/lib/cups/filter/pdftopdf) exited with no errors.
D [11/Nov/2016:16:13:06 +0800] [Job 23] Color Manager: Calibration Mode/Off
D [11/Nov/2016:16:13:06 +0800] [Job 23] Calling FindDeviceById(cups-hp-m1216nfh)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Found device /org/freedesktop/ColorManager/devices/cups_hp_m1216nfh
D [11/Nov/2016:16:13:06 +0800] [Job 23] Calling org.freedesktop.ColorManager.Device.Get(ProfilingInhibitors)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Calling FindDeviceById(cups-hp-m1216nfh)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Found device /org/freedesktop/ColorManager/devices/cups_hp_m1216nfh
D [11/Nov/2016:16:13:06 +0800] [Job 23] Calling GetProfileForQualifiers(Gray.Plain....)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Failed to send: org.freedesktop.ColorManager.Device.NothingMatched:nothing matched expression \Gray.Plain.,Gray.Plain.*,Gray.*.,Gray.*.*,*\‘
D [11/Nov/2016:16:13:06 +0800] [Job 23] Failed to get profile filename for cups-hp-m1216nfh
D [11/Nov/2016:16:13:06 +0800] [Job 23] Color Manager: no profiles specified in PPD
D [11/Nov/2016:16:13:06 +0800] [Job 23] Set job-printer-state-message to "Color Manager: no profiles specified in PPD", current level=INFO
D [11/Nov/2016:16:13:06 +0800] [Job 23] Color Manager: ICC Profile: None
D [11/Nov/2016:16:13:06 +0800] [Job 23] Ghostscript using Any-Part-of-Pixel method to fill paths.
D [11/Nov/2016:16:13:06 +0800] [Job 23] Ghostscript command line: gs -dQUIET -dPARANOIDSAFER -dNOPAUSE -dBATCH -dNOINTERPOLATE -dNOMEDIAATTRS -sstdout=%stderr -sOutputFile=%stdout -sDEVICE=cups -sMediaType=Plain -sOutputType=0 -r600x600 -dMediaPosition=7 -dDEVICEWIDTHPOINTS=612 -dDEVICEHEIGHTPOINTS=792 -dcupsBitsPerColor=1 -dcupsColorOrder=0 -dcupsColorSpace=3 -dcupsRowCount=1 -dcupsRowStep=2 -dcupsInteger0=2 -scupsPageSizeName=Letter -I/usr/share/cups/fonts -c \<</.HWMargins[12.000000 12.000000 12.000000 12.000000] /Margins[0 0]>>setpagedevice\‘ -f -_
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[0]=\"CUPS_CACHEDIR=/var/cache/cups\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[1]=\"CUPS_DATADIR=/usr/share/cups\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[2]=\"CUPS_DOCROOT=/usr/share/cups/doc\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[3]=\"CUPS_FONTPATH=/usr/share/cups/fonts\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[4]=\"CUPS_REQUESTROOT=/var/spool/cups\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[5]=\"CUPS_SERVERBIN=/usr/lib/cups\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[6]=\"CUPS_SERVERROOT=/etc/cups\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[7]=\"CUPS_STATEDIR=/run/cups\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[8]=\"HOME=/var/spool/cups/tmp\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[9]=\"PATH=/usr/lib/cups/filter:/usr/bin:/usr/bin:/bin:/usr/bin\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[10]=\"SERVER_ADMIN=root@T7\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[11]=\"SOFTWARE=CUPS/2.2.1\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[12]=\"TMPDIR=/var/spool/cups/tmp\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[13]=\"USER=root\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[14]=\"CUPS_MAX_MESSAGE=2047\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[15]=\"CUPS_SERVER=/run/cups/cups.sock\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[16]=\"CUPS_ENCRYPTION=IfRequested\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[17]=\"IPP_PORT=631\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[18]=\"CHARSET=utf-8\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[19]=\"LANG=en_US.UTF-8\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[20]=\"PPD=/etc/cups/ppd/hp-m1216nfh.ppd\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[21]=\"RIP_MAX_CACHE=128m\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[22]=\"CONTENT_TYPE=application/vnd.cups-pdf-banner\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[23]=\"DEVICE_URI=socket://172.168.10.98\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[24]=\"PRINTER_INFO=HLYT-Printer-Black\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[25]=\"PRINTER_LOCATION=HLYT\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[26]=\"PRINTER=hp-m1216nfh\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[27]=\"PRINTER_STATE_REASONS=none\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[28]=\"CUPS_FILETYPE=document\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[29]=\"FINAL_CONTENT_TYPE=application/vnd.cups-raster\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] envp[30]=\"AUTH_INFO_REQUIRED=none\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] Start rendering...
D [11/Nov/2016:16:13:06 +0800] [Job 23] Set job-printer-state-message to "Start rendering...", current level=INFO
D [11/Nov/2016:16:13:06 +0800] [Job 23] Processing page 1...
D [11/Nov/2016:16:13:06 +0800] [Job 23] Set job-printer-state-message to "Processing page 1...", current level=INFO
D [11/Nov/2016:16:13:06 +0800] [Job 23] STATE: +hplip.plugin-error
D [11/Nov/2016:16:13:06 +0800] [Job 23] prnt/hpcups/HPCupsFilter.cpp 486: m_Job initialization failed with error = 48
D [11/Nov/2016:16:13:06 +0800] [Job 23] PID 5881 (/usr/lib/cups/filter/hpcups) stopped with status 1.
D [11/Nov/2016:16:13:06 +0800] [Job 23] Hint: Try setting the LogLevel to "debug" to find out more.
D [11/Nov/2016:16:13:06 +0800] [Job 23] hrDeviceDesc=\"HP LaserJet Professional M1216nfh MFP\"
D [11/Nov/2016:16:13:06 +0800] [Job 23] prtGeneralCurrentLocalization type is 5, expected 2!
D [11/Nov/2016:16:13:06 +0800] [Job 23] backendWaitLoop(snmp_fd=7, addr=0x55740d4f2128, side_cb=0x55740bc95230)
D [11/Nov/2016:16:13:06 +0800] [Job 23] Connecting to 172.168.10.98:9100
D [11/Nov/2016:16:13:06 +0800] [Job 23] Connecting to printer.
D [11/Nov/2016:16:13:06 +0800] [Job 23] STATE: -connecting-to-device
D [11/Nov/2016:16:13:06 +0800] [Job 23] Connected to printer.
D [11/Nov/2016:16:13:06 +0800] [Job 23] Connected to 172.168.10.98:9100...
D [11/Nov/2016:16:13:06 +0800] [Job 23] backendRunLoop(print_fd=0, device_fd=8, snmp_fd=7, addr=0x55740d4f2128, use_bc=1, side_cb=0x55740bc95230)
D [11/Nov/2016:16:13:06 +0800] [Job 23] STATE: +cups-waiting-for-job-completed
D [11/Nov/2016:16:13:06 +0800] [Job 23] Waiting for printer to finish.
D [11/Nov/2016:16:13:06 +0800] [Job 23] PID 5882 (/usr/lib/cups/backend/socket) exited with no errors.
D [11/Nov/2016:16:13:06 +0800] [Job 23] Processing page 2...
D [11/Nov/2016:16:13:06 +0800] [Job 23] Rendering completed
D [11/Nov/2016:16:13:06 +0800] [Job 23] PID 5880 (/usr/lib/cups/filter/gstoraster) exited with no errors.
D [11/Nov/2016:16:13:06 +0800] [Job 23] End of messages
D [11/Nov/2016:16:13:06 +0800] [Job 23] printer-state=3(idle)
D [11/Nov/2016:16:13:06 +0800] [Job 23] printer-state-message="Rendering completed"
D [11/Nov/2016:16:13:06 +0800] [Job 23] printer-state-reasons=hplip.plugin-error
error_log

 

第六:直接使用hplip的工具安装,不使用cups

hp-setup -i 172.168.10.98

  不需要指定驱动,自动识别,自动安装。

  完成向导,打印测试页,好用!

总结:HP的打印机,就用HP的工具装,节约时间。: )

------------------------------------------- 

后续:

  因为并不知道为什么cups不好使,而小伙伴们都说重来没遇见过不好使的时候,所以我又尝试调查了一下,希望找到原因。

hp-setup之后,使用hp-check命令,可以查看到所以打印机的信息。成功添加的打印机使用了一个新生产的ppd,

/etc/cups/ppd/HP_LaserJet_Professional_M1216nfh_MFP.ppd

与原ppd比较如下:

152 (T7) ~/Src/tss/tss_sys
>>> diff 1 2
3c3
< *%%%% Created by the CUPS PPD Compiler CUPS v2.1.3.
---
> *%%%% Created by the CUPS PPD Compiler CUPS v2.2.1.
29c29
< *cupsVersion: 2.1
---
> *cupsVersion: 2.2
153 (T7) 1 ~/Src/tss/tss_sys
>>>                            

所以,我一度以为是ppd里边这两行区别导致的问题,只要有了新ppd,就可以正常使用了(另外,这个新PPD是从哪来的?

之后,我使用这个新ppd用cups重新加载了一次,未修复,现象与之前保持一致。

 

[daily] linux添加打印机