我尝试从此PDF 文件生成位图。我的代码如下:
mFileDescriptor = ParcelFileDescriptor.open(pdfFile, ParcelFileDescriptor.MODE_READ_ONLY);
// This is the PdfRenderer we use to render the PDF.
if (mFileDescriptor != null) {
mPdfRenderer = new PdfRenderer(mFileDescriptor);
}
if (mPdfRenderer != null) {
for (int i = 0; i < mPdfRenderer.getPageCount(); i++) {
printPage(i);
}
}
....
private void printPage(int index) {
byte[] img;
if (mPdfRenderer.getPageCount() <= index) {
return;
}
// Make sure to close the current page before opening another one.
if (null != mCurrentPage) {
mCurrentPage.close();
}
// Use `openPage` to open a specific page in PDF.
mCurrentPage = mPdfRenderer.openPage(index);
int width = (int)(203.0 / 72.0 * mCurrentPage.getWidth() + 0.5);
int height = (int)(203.0 / 72.0 * mCurrentPage.getHeight() + 0.5);
// Important: the destination bitmap must be ARGB (not RGB).
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
mCurrentPage.render(bitmap, null, null, PdfRenderer.Page.RENDER_MODE_FOR_PRINT);
try {
sendImageToPrinter(PrinterEventsProto.Image.parseFrom(bitmap), getApplicationContext());
} catch (InvalidProtocolBufferException e) {
e.printStackTrace();
}
}
而对应的位图是我不明白这个黑色边框来自哪里的位图。任何想法 ?