This class encapsulates information about a document for printing
purposes. This meta-data is used by the platform and print services,
components that interact with printers. For example, this class
contains the number of pages contained in the document it describes and
this number of pages is shown to the user allowing him/her to select
the range to print. Also a print service may optimize the printing
process based on the content type, such as document or photo.
Instances of this class are created by the printing application and
passed to the {@link PrintDocumentAdapter.LayoutResultCallback#onLayoutFinished(
PrintDocumentInfo, boolean) PrintDocumentAdapter.LayoutResultCallback.onLayoutFinished(
PrintDocumentInfo, boolean)} callback after successfully laying out the
content which is performed in {@link PrintDocumentAdapter#onLayout(PrintAttributes,
PrintAttributes, android.os.CancellationSignal, PrintDocumentAdapter.LayoutResultCallback,
android.os.Bundle) PrintDocumentAdapter.onLayout(PrintAttributes,
PrintAttributes, android.os.CancellationSignal,
PrintDocumentAdapter.LayoutResultCallback, android.os.Bundle)}.
An example usage looks like this:
. . .
public void onLayout(PrintAttributes oldAttributes, PrintAttributes newAttributes,
CancellationSignal cancellationSignal, LayoutResultCallback callback,
Bundle metadata) {
// Assume the app defined a LayoutResult class which contains
// the layout result data and that the content is a document.
LayoutResult result = doSomeLayoutWork();
PrintDocumentInfo info = new PrintDocumentInfo
.Builder("printed_file.pdf")
.setContentType(PrintDocumentInfo.CONTENT_TYPE_DOCUMENT)
.setPageCount(result.getPageCount())
.build();
callback.onLayoutFinished(info, result.getContentChanged());
}
. . .
|