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).

Prerequisites

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 is being chased by zombies.

About the Sample App

The preview of this section will not appear here for a while, due to a time machine mishap.

Printing a Bitmap

The preview of this section was whisked away by a shark-infested tornado.

Printing an HTML Document

The preview of this section is en route to Mars.

Printing a PDF File

The preview of this section was stepped on by Godzilla.

Printing Using a Canvas

The preview of this section is [REDACTED].

Print Jobs

The preview of this section was abducted by space aliens.

Printing, Threads, and Services

The preview of this section was whisked away by a shark-infested tornado.

Printing Prior to Android 4.4

The preview of this section will not appear here for a while, due to a time machine mishap.

HTML Generation

The preview of this section is presently indisposed.

PDF Generation Options

The preview of this section was the victim of a MITM ('Martian in the middle') attack.