简体   繁体   中英

How to print PDF files in Android?

I have some PDF files in the app and I want to enable users to print them.

I have seen PrinterManager class but it looks like too much boilerplate code.

Is there some kind of Intent that will open some system screen to handle printing like choosing printer and printing?

I have used a few PDF apps and they are opening this screen for printing.

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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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