一、ubuntu安装cups打印
在Ubuntu上安装CUPS(打印系统)的步骤如下:
1、打开终端。
2、更新软件包列表:
sudo apt update
3、安装CUPS:
sudo apt install cups
4、安装foomatic-filters与ghostscript:
sudo apt-get install foomatic-filters
sudo apt-get install ghostscript
sudo apt-get install cups --reinstall
sudo /etc/init.d/cups restart
5、安装完成后,配置并启动CUPS服务:
-
sudo service cups start
-
你可以通过以下命令检查CUPS服务的状态:通过浏览器访问CUPS的网页界面,在地址栏输入:
http://localhost:631
6、以上步骤会在Ubuntu系统上安装CUPS,并启动打印服务。如果你的系统中还没有安装Web浏览器,你可以在安装CUPS之后,通过命令行使用lpinfo
和lpadmin
工具来配置打印机。
7、安装遇到的问题
7、安装遇到的问题
Failed to connect to bus: No such file or directory
sudo /etc/init.d/dbus start
Failed to start cups.service: Launch helper exited with unknown return code 1
sudo /etc/init.d/cups restart
8、打印应用与测试:
添加打印机:
lpadmin -p epson-xxx -E -v "ipp://11.22.33.44/ipp/print" -m everywhere
lpadmin -p EPSON-L3251 -E -v ipp://11.22.33.44/ipp/print -m everywhere
lpadmin -p HP_xxx -E -v ipp://11.22.33.44/ipp/print -m everywhere
9、设置默认打印队列:
如果你有一个或多个打印队列可用,但是没有设置默认,你可以使用 lpoptions
命令来设置默认打印队列。假设你有一个名为 printer1
的打印队列,你可以这样设置它为默认:
lpoptions -d epson-xxx
lpoptions -d HP_xxx
10、查看Epson打印机3250系列ppd驱动文件状态及位置
lpinfo -m | grep 3250
foomatic-db-compressed-ppds:0/ppd/foomatic-ppd/Epson-ActionPrinter_3250-ap3250.ppd Epson ActionPrinter 3250 Foomatic/ap3250 (recommended)
~$ find / -name "Epson*" 2>/dev/null
/etc/cups/ppd/Epson_L3251_Printer.ppd
/etc/cups/ppd/Epson_L3251_Printer.ppd.O
11、开始打印:
lp xxx.pdf
lp -o media=A4 -o resolution=600dpi xxx.pdf
12、删除打印机:
lpadmin -x myprinter
13、打印机队列状态
~$ lpstat -p
二、Andoird系统各种打印机PDF打印(插件调用方式)
建议使用各打印机厂商提供的打印机插件apk程序安装,然后使用插件调用方式调用打印。
如1、Hp的com.hp.android.printservice_xxx.apk;
2、Epson的EpsoniPrint.apk;
3、Canon的Canon_PR_Biz.apk;
4、Sansung的com.sec.print.mobileprint_v4.xxx.apk等。
插件调用代码:
/**
* pdf打印
*/
private fun sharePdf(pdfPath: String){
val pdfFile = File(pdfPath)
if (pdfFile.exists()) {
val shareIntent = Intent(Intent.ACTION_SEND)
shareIntent.setType("application/pdf")
val pdfUri: Uri = Uri.fromFile(pdfFile)
shareIntent.putExtra(Intent.EXTRA_STREAM, pdfUri)
startActivity(Intent.createChooser(shareIntent, "Pdf Report"))
}
else {
Toast.makeText(this, "PDF file not found", Toast.LENGTH_SHORT).show()
}
}
三、Android ndk交叉编译CUPS
过程较为复杂,依赖较多,集成较为麻烦,暂不推荐。
1、下载NDK(NDK 下载 | Android NDK | Android Developers)
2、解压、安装NDK、配置交叉编译环境
android-ndk-r21e$ ./build/tools/make_standalone_toolchain.py --arch arm --api 24 --install-dir /home/toolchain
# vim ~/.bash_profile
export NDK=/home/xxx/tools/android-ndk-r21e
export PATH=${NDK}:${NDK}/../toolchain/bin:${PATH}
export NDK_PROJECT_PATH=${NDK}
export CXX=armv7a-linux-androideabi24-clang++
export CC=armv7a-linux-androideabi24-clang
3、下载cups、cups-filter及其依赖包
GitHub - jianglei12138/cups: cups for android (UNIX通用打印系统)
4、解压、交叉编译cups2.1.3
4.1 替换local头文件及拷贝so库(GitHub - jianglei12138/liblocale: locale for android)
下载 lcoale 支持库和库 ,然后将标头 locale.h 放在 toolchain-folder/sysroot/usr/include(override) 下,并将共享库 liblocale.so 放在 toolchain-folder/sysroot/usr/lib 下
4.2 配置cups
./configure --host=arm-linux-androideabi --disable-dbus --prefix=/system/usr/root --with-cups-user=system --with-cups-group=system --with-system-groups=root
5、编译
#需要重新编译avahi-master,并拷贝头文件和库,以及local头文件和库,否则会出现缺头文件和库符号错误
make
make install
6、编译2.4.10
./configure --host=arm-linux-androideabi --disable-dbus --without-tls --disable-pam --prefix=/system/usr/root --with-cups-user=system --with-cups-group=system --with-system-groups=root
#打入补丁
patch -p1 < ../cups-2.4.10-android-port.patch
编译
make
make install DESTDIR=/home