简体   繁体   English

如何在 Android 中打印 PDF 文件?

[英]How to print PDF files in Android?

I have some PDF files in the app and I want to enable users to print them.我在应用程序中有一些 PDF 文件,我想让用户打印它们。

I have seen PrinterManager class but it looks like too much boilerplate code.我见过 PrinterManager 类,但它看起来像太多的样板代码。

Is there some kind of Intent that will open some system screen to handle printing like choosing printer and printing?是否有某种 Intent 会打开一些系统屏幕来处理打印,例如选择打印机和打印?

I have used a few PDF apps and they are opening this screen for printing.我使用了一些 PDF 应用程序,他们正在打开此屏幕进行打印。

How I can make something like this?我怎么能做出这样的东西?

在此处输入图片说明

If you don't want create your own code to print the document in your app.如果您不想创建自己的代码来打印应用程序中的文档。

You could try to implement an Intent to launch Chrome or other browser passing the path of the file as Uri and open the PDF in the browser, then the user could print the document using the browser.您可以尝试实现 Intent 以启动 Chrome 或其他浏览器,将文件路径作为 Uri 传递并在浏览器中打开 PDF,然后用户可以使用浏览器打印文档。

Launching the intent:启动意图:

//Launch the intent to open the file with default browser.
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(path_to_file));
startActivity(i);

You can print using Chrome: Settings -> Share -> Choose Print and select your printer.您可以使用 Chrome 打印:设置 -> 共享 -> 选择打印并选择您的打印机。

I hope it can helps you.我希望它能帮助你。

My Requirement also same.我的要求也一样。 I found solution and tested on mobile.我找到了解决方案并在移动设备上进行了测试。 Solution exactly what you are looking.解决方案正是您正在寻找的。 Please refer.请参考。 https://github.com/commonsguy/cw-omnibus/tree/FINAL/Printing/PrintManager https://github.com/commonsguy/cw-omnibus/tree/FINAL/Printing/PrintManager

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM