Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/225.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android PdfDocument.writeTo导致大型文档的ANR_Android - Fatal编程技术网

Android PdfDocument.writeTo导致大型文档的ANR

Android PdfDocument.writeTo导致大型文档的ANR,android,Android,我正在使用本机Android库PrintedPdfDocument创建PdfDocument。当总页数大约小于15时,下面的代码可以正常工作。然而,对于较大的文档,调用会导致ANR,系统会终止我的应用程序。我正在AsyncTask中执行代码。这在Android L(三星Note PRO)上尤其是一个问题;Android M可以可靠地处理多达40个页面(经过测试) 我应该如何使用这些代码在Android L上创建大型PDF文档?非常感谢您的帮助。尝试使用可能有帮助的mupdfyou@parikdh

我正在使用本机Android库PrintedPdfDocument创建PdfDocument。当总页数大约小于15时,下面的代码可以正常工作。然而,对于较大的文档,调用会导致ANR,系统会终止我的应用程序。我正在AsyncTask中执行代码。这在Android L(三星Note PRO)上尤其是一个问题;Android M可以可靠地处理多达40个页面(经过测试)


我应该如何使用这些代码在Android L上创建大型PDF文档?非常感谢您的帮助。

尝试使用可能有帮助的mupdfyou@parikdhakan谢谢你的建议。MuPDF不是免费的-它是根据AGPL授权的。@Roy你有没有找到解决这个问题的方法?
// open a new document
document = new PrintedPdfDocument(_activity, printAttributes);
// crate a page description
PdfDocument.PageInfo pageInfo = new PdfDocument.PageInfo.Builder(pageWidth, pageHeight, pageIndex).create();
page = document.startPage(pageInfo);
content.draw(page.getCanvas());
// finish the page
document.finishPage(page);

try
{
       File pdfPath = new File(FILE_PATH);
       // This statement causing ANR
       document.writeTo(new FileOutputStream(pdfPath));
}
catch (Exception e)
{
    // log
}
// close the document
document.close();