[原]CUPS-PDF编译安装

作者: 锦城牛仔 | 来源:发表于2019-07-29 17:10 被阅读34次

CUPS相关知识,并尝试搭建驱动开发环境。由于目前没有实体打印机,使用cups-pdf打印机代替。

开发环境:

Linux 4.4.0-31-generic #50~14.04.1-Ubuntu SMP Wed Jul 13 01:07:32 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

环境搭建目标:

为方便开发调试(需要看源码)都采用编译安装

1. 编译安装CUPS及相关依赖

2. 编译安装CUPS-PDF打印机

3. 尝试打印

编译安装过程:


1.下载并安装cups

1.1下载cups

到git上https://github.com/apple/cups,找到最新的cups版本2.2.9,直接下载

https://github.com/apple/cups/releases/download/v2.2.9/cups-2.2.9-source.tar.gz

1.2解压带源码的cups包

tar xzvf cups-2.2.9-source.tar.gz

得到目录

cups-2.2.9

1.3根据INSTALL.md进行安装

根据要求安装依赖库

sudo apt-get install autoconf build-essential libavahi-client-dev libgnutls28-dev libkrb5-dev libnss-mdns libusb-1.0-0-dev zlib1g-dev

sudo apt-get install libpam-dev

apt-get install libsystemd-daemon-dev

1.4执行configure

./configure

一般这一步会出现多次失败,每一次都会提示系统缺少的依赖库,使用apt-cache search xxx找到相应的依赖库进行安装就可以了。configure成功之后就可以编译了。其中,有一个很重要的依赖库GNUTLS本身又依赖很多库,需要折腾一番。

1.5执行make

./make

这一步也有可能编译失败,如果系统中安装有多个libcups.so有可能默认找到的库不正确,需要进行调整,确保编译通过

1.6执行make check

./make check

检查编译结果

1.7执行make install

./make install

完成安装

1.8 cups安装完了?现在cups本身算是安装上了,但是必须要安装GPL Ghostscript和Open Printing CUPS filters。




2. 编译GNUTLS库

2.1 Gnutls库主页

https://www.gnutls.org/manual/gnutls.html

2.2 Gnutls下载页

https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6

2.3 下载链接

https://www.gnupg.org/ftp/gcrypt/gnutls/v3.6/gnutls-3.6.9.tar.xz

解压:

xd -d gnutls-3.6.9.tar.xz

tar xvf gnutls-3.6.9.tar

2.4 安装gnutls依赖库

GnuTLS依赖nettle、gmplib库,还有asn.1库,以及p11-kit库等,根据系统已经安装的软件不同,遇到依赖也不同。可以通过运行./configure查看缺少的依赖库

2.4.1 安装nettle

下载页

https://ftp.gnu.org/gnu/nettle/

下载nettle 3.4.1

https://ftp.gnu.org/gnu/nettle/nettle-3.4.1.tar.gz

解压

tar xzvf nettle-3.4.1.tar.gz

cd nettle-3.4.1

./configure --enable-mini-gmp

./make

./make install

注意,必须加上--enable-mini-gmp,要不然编译出来缺少一个库

2.4.2 安装gmlib

https://gmplib.org/download/gmp/gmp-6.1.2.tar.lz

解压

lzip -d gmp-6.1.2.tar.lz

tar xvf gmp-6.1.2.tar

cd gmp-6.1.2

./configure

./make

./make check

./make install

2.4.3 安装p11-kit和asn.1

apt-get install libp11-kit-dev

apt-get install libtasn1-6-dev

2.4.4 编译安装gnutls

cd gnutls-3.6.8

./configure

./make check install


3.安装Open Printing CUPS filters

Cups和Open Printer CUPS filters的关系是,早期版本他们是一体的,后来Open Printer CUPS filters单独分出来维护,CUPS只做Linux打印系统。更多的filters和backends都包括在Open Printer CUPS filters包中。

3.1 下载Open Printing CUPS filters

git地址:

https://github.com/OpenPrinting/cups-filters

下载包:

https://github.com/OpenPrinting/cups-filters/releases/download/release-1-25-1/cups-filters-1.25.1.tar.gz

解压

tar xzvf cups-filters-1.25.1.tar.gz

cd cups-filters-1.25.1

3.1.1 生成configure

./autogen.sh

生成对应的configure

3.1.2 执行configure和编译

./configure

这一步会提示各种需要的包,根据提示进行安装即可。

./make

./make install


4.安装GPL Ghostscript

下载包

https://github.com/ArtifexSoftware/ghostpdl-downloads/releases/download/gs925/ghostscript-9.25.tar.gz

解压

tar xzvf ghostscript-9.25.tar.gz

cd ghostscript-9.25

./configure

make

make install

特别注意,如果不使用编译安装Ghostscript,而使用apt-get install安装的话,很可能出现因为安装Ghostscript而覆盖原有的libcups.so包,导致其中未包含cups.2.2.9中的函数。建议如果是要自己开发的话,这一步要编译安装。




5.安装cups-pdf驱动

网址:https://www.cups-pdf.de/

5.1下载包

https://www.cups-pdf.de/src/cups-pdf_3.0.1.tar.gz

解压tar xzvf cups-pdf_3.0.1.tar.gz

cd cups-pdf-3.0.1

5.2编译

cd src

gcc -O9 -s cups-pdf.c -o cups-pdf -lcups

5.3拷贝到指定位置

编译成功之后,得到可执行文件cups-pdf

ls -al

-rwxr-xr-x 1 root root  138312  7月 25 14:53 cups-pdf*

-rw-r--r-- 1 1133 staff  35765  7月 25 14:53 cups-pdf.c

-rw-r--r-- 1 1133 staff  4997  2月 24  2017 cups-pdf.h

将cups-pdf拷贝到cups的backends目录

cp -rf cups-pdf /usr/lib/cups/backend

5.4拷贝ppd

将CUPS-PDF_opt.ppd拷贝到/usr/share/cups/model

使用lpinfo -m命令查看

lsb/usr/cupsfilters/Fuji_Xerox-DocuPrint_CM305_df-PDF.ppd Fuji Xerox

drv:///sample.drv/dymo.ppd Dymo Label Printer

drv:///sample.drv/epson9.ppd Epson 9-Pin Series

drv:///sample.drv/epson24.ppd Epson 24-Pin Series

drv:///generic-brf.drv/gen-brf.ppd Generic Braille embosser, 1.0

CUPS-PDF_opt.ppd Generic CUPS-PDF Printer (w/ options)

drv:///cupsfilters.drv/pwgrast.ppd Generic IPP Everywhere Printer


6.配置打印机

lpadmin -p cups-pdf -E -v cups-pdf:/ -m CUPS-PDF_opt.ppd

查看打印机

lpstat -a

cups-pdf 自从 2019年07月24日 星期三 17时59分46秒 开始接受请求

尝试打印

lpr -P cups-pdf /etc/passwd

查看打印文件

ls -al /var/spool/cups-pdf/root/passwd__l_cups-pdf_root.pdf

-rw------- 1 root root 13614  7月 29 14:52 /var/spool/cups-pdf/root/passwd__l_cups-pdf_root.pdf


7.Debug编译和查看日志

开发需要看日志,在编译cups时,可以添加相应的debug选项,这样就可以成功输出日志。

cups日志在这个目录:

ls -al /var/log/cups

total 1256

drwxrwxrwx  2 root root      4096  7月 29 14:36 ./

drwxrwxrwx 14 root syslog    4096  7月 29 14:36 ../

-rw-r--r--  1 root lp        763  7月 29 14:57 access_log

-rw-r--r--  1 root lp      125231  7月 29 14:57 error_log

-rwxrwxrwx  1 root adm          0  7月 22 14:47 page_log*

相关文章

  • [原]CUPS-PDF编译安装

    CUPS相关知识,并尝试搭建驱动开发环境。由于目前没有实体打印机,使用cups-pdf打印机代替。 开发环境: L...

  • [原]lpr成功打印中文

    本文接上篇《cups-pdf编译安装》,内容都为本身根据项目经验总结,可以转载但请注明出处。作者简书id: weo...

  • 未能加载文件或程序集“ICSharpCode.SharpZipL

    解决:重新安装NPOI,点击“管理NuGet程序包”,搜索NPOI,然后安装,重新编译,运行即可。(安装前记得把原...

  • zabbix版本替换升级

    前言:原环境运行在编译环境下的LNMP中,原版本也为编译安装,现尝试升级版本,这里选择移除原版本安装新版本的方式,...

  • Linux下关于Nginx的安装与使用

    2019-3-4更新:原内容适合是编译安装,并且没有编译ssl模块,如果需要自己添加。centos7还是推荐yum...

  • 搭建并配置LAMP/LNMP环境

    如何编译安装软件编译安装是Linux安装软件的重要方式编译前的准备工作:./configure编译:make安装:...

  • Linux下编译Xmrig

    安装依赖 Ubuntu CentOS 安装 创建编译文件夹 编译安装 基本编译方式 静态编译方式 编译完成后使用l...

  • php 手动编译添加扩展

    在完成 php的编译安装后, 发现没有编译某此模块。手动添加安装。php源码编译安装 编译安装 在php源码包中 ...

  • 编译安装LNMP

    编译安装nginx 编译安装PHP 配置Nginx+PHP 安装MySQL

  • 编译安装LNMP2

    编译安装nginx 编译安装PHP 配置Nginx+PHP 安装MySQL

网友评论

    本文标题:[原]CUPS-PDF编译安装

    本文链接:https://www.haomeiwen.com/subject/ryfirctx.html