PrintAdapter.java 文件源码

java
阅读 23 收藏 0 点赞 0 评论 0

项目:cards-app 作者:
@Override
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination,
        CancellationSignal cancellationSignal, WriteResultCallback callback) {
    // TODO Auto-generated method stub

     // Iterate over each page of the document,
    // check if it's in the output range.
    for (int i = 0; i < 2; i++) {
        // Check to see if this page is in the output range.
            // If so, add it to writtenPagesArray. writtenPagesArray.size()
            // is used to compute the next output page index.
            PdfDocument.Page page = document.startPage(i);

            // check for cancellation
            if (cancellationSignal.isCanceled()) {
                callback.onWriteCancelled();
                document.close();
                document = null;
                return;
            }

            // Draw page content for printing
            drawPage(page,i);

            // Rendering is complete, so page can be finalized.
            document.finishPage(page);
    }

    // Write PDF document to file
    try {
        document.writeTo(new FileOutputStream(
                destination.getFileDescriptor()));
    } catch (IOException e) {
        callback.onWriteFailed(e.toString());
        return;
    } finally {
        document.close();
        document = null;
    }
    PageRange[] writtenPages = {PageRange.ALL_PAGES};
    // Signal the print framework the document is complete
    callback.onWriteFinished(writtenPages);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号