一、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
9、设置默认打印队列:
如果你有一个或多个打印队列可用,但是没有设置默认,你可以使用 lpoptions
命令来设置默认打印队列。假设你有一个名为 printer1
的打印队列,你可以这样设置它为默认:
lpoptions -d epson-xxx
10、开始打印:
lp -o media=A4 -o resolution=600dpi xxx.pdf
二、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
过程较为复杂,依赖较多,集成较为麻烦,暂不推荐。