在我的Android打印类中,有时我会在onWrite函数中遇到PageRange的参数为null,它是一个覆盖函数,并且值是从Android框架传递的,我想找到它为什么有时为空的原因(不是100%)?这是设备问题吗?有没有人见过这个?代码和日志如下:
class PdfFragmentPrintDocumentAdapter extends PrintDocumentAdapter{
public void onWrite(PageRange[] pages, ParcelFileDescriptor destination, CancellationSignal cancellationSignal, WriteResultCallback callback) {
........
callback.onWriteFinished(pages);
}
.........
java.lang.IllegalArgumentException: pages cannot be empty
at android.print.PrintManager$PrintDocumentAdapterDelegate$MyWriteResultCallback.onWriteFinished(PrintManager.java:961)
at com.microsoft.pdfviewer.PdfFragmentPrint$PdfFragmentPrintDocumentAdapter$2.run(PdfFragmentPrint.java:265)
at com.microsoft.pdfviewer.PdfFragmentPrint$PdfFragmentPrintDocumentAdapter.implementOnWriteInDedicatedThread(PdfFragmentPrint.java:278)
at com.microsoft.pdfviewer.PdfFragmentPrint$PdfFragmentPrintDocumentAdapter.onWrite(PdfFragmentPrint.java:213)
at android.print.PrintManager$PrintDocumentAdapterDelegate$MyHandler.handleMessage(PrintManager.java:792)
答案 0 :(得分:0)
除非您明确提取页面,否则请调用onWriteFinished(new PageRange[]{PageRange.ALL_PAGES})
并编写整个pdf。在这种情况下,即使传递了页面范围,系统也会渲染并仅打印所选页面。