我正在我的 Android 应用程序中创建 pdf 页面。为了保持与使用 Kitkat (API 19) 的旧设备的兼容性,我使用了带有PrintedPdfDocument
andPdfDocument.Page
而不是PdfRenderer
(需要 API 21)的工作流程
问题是,图像似乎是未压缩存储的。我的测试图像(大约 2000x700 像素)大约 3Mb 大。
据我所知,这只发生在 Android 5 上。更高版本会生成更小的(压缩)图像(大约 200kb)。
不幸的是,我找不到很多配置输出的方法。
我的打印属性如下所示:
PrintAttributes printAttributes = new PrintAttributes.Builder()
.setMediaSize(mediaSize)
.setColorMode(PrintAttributes.COLOR_MODE_COLOR)
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
.build();
因此,除了设置为 COLOR_MODE_MONOCHROME 之外,我看不到任何可以尝试的东西。
有人有什么主意吗?对我来说,唯一的方法是寻找 API 级别,使用更新PdfRenderer
的 API 21+ 和我对 Kitkat 的原始解决方案。
有没有更好的方法来代替两种不同的工作流程?