FileDocCategorySizeDatePackage
PrintDocument.javaAPI DocAndroid 5.1 API3098Thu Mar 12 22:22:10 GMT 2015android.printservice

PrintDocument

public final class PrintDocument extends Object
This class represents a printed document from the perspective of a print service. It exposes APIs to query the document and obtain its data.

Note: All methods of this class must be executed on the main application thread.

Fields Summary
private static final String
LOG_TAG
private final android.print.PrintJobId
mPrintJobId
private final IPrintServiceClient
mPrintServiceClient
private final android.print.PrintDocumentInfo
mInfo
Constructors Summary
PrintDocument(android.print.PrintJobId printJobId, IPrintServiceClient printServiceClient, android.print.PrintDocumentInfo info)


       
              
        mPrintJobId = printJobId;
        mPrintServiceClient = printServiceClient;
        mInfo = info;
    
Methods Summary
public android.os.ParcelFileDescriptorgetData()
Gets the data associated with this document.

Note: It is a responsibility of the client to open a stream to the returned file descriptor, fully read the data, and close the file descriptor.

return
A file descriptor for reading the data.

        PrintService.throwIfNotCalledOnMainThread();
        ParcelFileDescriptor source = null;
        ParcelFileDescriptor sink = null;
        try {
            ParcelFileDescriptor[] fds = ParcelFileDescriptor.createPipe();
            source = fds[0];
            sink = fds[1];
            mPrintServiceClient.writePrintJobData(sink, mPrintJobId);
            return source;
        } catch (IOException ioe) {
            Log.e(LOG_TAG, "Error calling getting print job data!", ioe);
        } catch (RemoteException re) {
            Log.e(LOG_TAG, "Error calling getting print job data!", re);
        } finally {
            if (sink != null) {
                try {
                    sink.close();
                } catch (IOException ioe) {
                    /* ignore */
                }
            }
        }
        return null;
    
public android.print.PrintDocumentInfogetInfo()
Gets the {@link PrintDocumentInfo} that describes this document.

return
The document info.

        PrintService.throwIfNotCalledOnMainThread();
        return mInfo;