我正在尝试使用itextpdf libray将 android 视图转换为 PDF,但我只获得了 pdf 的一半视图。我在这里分享我的代码
获取视图的代码
View v1 = getWindow().getDecorView().getRootView();
v1.setDrawingCacheEnabled(true);
screen = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);
将该视图转换为 pdf 的代码
try {
Document document = new Document();
PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
document.open();
ByteArrayOutputStream stream = new ByteArrayOutputStream();
screen.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
addImage(document, byteArray);
document.close();
} catch (Exception e) {
e.printStackTrace();
}