The following is the first few sections of a chapter from The Busy Coder's Guide to Android Development, plus headings for the remaining major sections, to give you an idea about the content of the chapter.

Printing and Document Generation

Mobile devices are continuing to close the gap on capabilities that had formerly been the sole province of desktop systems or servers. After all, if the vision is that people should be able to use phones and tablets instead of desktops and notebooks, phones and tablets need to do whatever it is that those people need to have done.

One such capability is the ability to print to networked printers. While various third-party printing options had been available for some time, it is only starting with the Android 4.4 release that the OS and framework itself has support for printing. Hence, at this time, a significant majority of Android devices will be natively capable of printing, and so users will be more likely to expect that your app supports such printing.

As it turns out, the print engine in Android is centered upon the PDF document format, and Android supports converting HTML into PDF, albeit on a somewhat limited basis.

The API seems simple and clean. It actually is simple and clean… so long as you are printing very simple contents (bitmaps or HTML). Once you get into anything more complicated than that, the threading alone starts to make things rather messy.

This chapter describes how to use the Android 4.4 print system, including how to print HTML and PDF files. It will also cover how to generate HTML and PDF files, whether for printing or for other purposes (e.g., reports to be emailed or uploaded somewhere).


Understanding this chapter requires that you have read the core chapters of this book. Also, you should read the chapter on advanced uses of WebView.

The Android Print System

The preview of this section did not survive Thanos's finger snap.

About the Sample App

The preview of this section was traded for a bag of magic beans.

Printing a Bitmap

The preview of this section was stepped on by Godzilla.

Printing an HTML Document

The preview of this section was abducted by space aliens.

Printing a PDF File

The preview of this section is unavailable right now, but if you leave your name and number at the sound of the tone, it might get back to you (BEEEEEEEEEEEEP!).

Printing Using a Canvas

The preview of this section is being chased by zombies.

Print Jobs

The preview of this section is in the process of being translated from its native Klingon.

Printing, Threads, and Services

The preview of this section was abducted by space aliens.

Printing Prior to Android 4.4

The preview of this section is in an invisible, microscopic font.

HTML Generation

The preview of this section is out seeking fame and fortune as the Dread Pirate Roberts.

PDF Generation Options

The preview of this section is en route to Mars.