使用下面的代碼來渲染pdf。這是一個嘗試/捕捉,並運行良好,顯示PDF。PDF渲染器將屏幕設置爲屏幕
問題是PDF文件對於屏幕來說太大了。有誰知道如何縮小比例以適應?
謝謝。
imageView = (ImageView) findViewById(R.id.imagePDF);
int REQ_WIDTH = imageView.getWidth();
int REQ_HEIGHT = imageView.getHeight();
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width12 = size.x;
int height12 = size.y;
Bitmap bitmap = Bitmap.createBitmap(width12, height12, Bitmap.Config.ARGB_4444);
File file = new File("/sdcard/Download/sample.pdf");
PdfRenderer renderer = new PdfRenderer(ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY));
if (currentPage < 0) {
currentPage = 0;
} else if (currentPage > renderer.getPageCount()) {
currentPage = renderer.getPageCount();
}
int pages;
pages = renderer.getPageCount();
Matrix m = imageView.getImageMatrix();
Rect rect = new Rect(0, 0, width12, height12);
renderer.openPage(currentPage).render(bitmap, rect, m, PdfRenderer.Page.RENDER_MODE_FOR_DISPLAY);
imageView.setImageMatrix(m);
imageView.setImageBitmap(bitmap);
imageView.invalidate();
ImageView.setScaleType(CENTER_INSIDE) –
imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); < - 這不起作用,PDF圖像仍然在屏幕的邊上運行 – AesculusMaximus
Rect和Matrix是可選的。如果兩者都傳遞null,會發生什麼? –