Changes

Jump to: navigation, search

Printing with the Android Printing Framework

No change in size, 21:02, 6 January 2014
no edit summary
</pre>
This method simply obtains a reference to the PrintManager service and instructs the web view instance to create a print adaptoradapter. A new string is created to store the name of the print job (in this case based on the name of the application and the word “Document”).
Finally, the print job is started by calling the print() method of the print manager, passing through the job name, print adaptor adapter and a set of default print attributes. If required, the print attributes could be customized to specify resolution (dots per inch), margin and color options.
=== Printing a Web Page ===
* Connect to the Android Print Manager
* Create a Custom Print Adaptor Adapter sub-classed from the PrintDocumentAdaptor PrintDocumentAdapter class
* Create a PdfDocument instance to represent the document pages
* Obtain a reference to the pages of the PdfDocument instance, each of which has associated with it a Canvas instance
* Notify the print framework that the document is ready to print
The custom print adaptor adapter outlined in the above steps needs to implement a number of methods which will be called upon by the Android system to perform specific tasks during the printing process. The most important of these are the onLayout() method which is responsible for re-arranging the document layout in response to the user changing settings such as paper size or page orientation, and the onWrite() method which is responsible for rendering the pages to be printed. This topic will be covered in detail in the chapter entitled [[An Android Custom Document Printing Tutorial]].
== Summary ==
The Android 4.4 KitKat release introduced the ability to print content from Android devices. Print output can be directed to suitably configured printers, a local PDF file or to the cloud via Google Drive. From the perspective of the Android application developer, these capabilities are available for use in applications by making use of the Printing framework. By far the easiest printing options to implement are those involving content in the form of images and HTML. More advanced printing may, however, be implemented using the custom document printing features of the framework.

Navigation menu