Android create and print pdf from layout view

南笙酒味 提交于 2019-12-05 07:55:22

Change to this,

        int measureWidth = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getWidth(), View.MeasureSpec.EXACTLY);
        int measuredHeight = View.MeasureSpec.makeMeasureSpec(page.getCanvas().getHeight(), View.MeasureSpec.EXACTLY);

        content.measure(measureWidth, measuredHeight);
        content.layout(0, 0, page.getCanvas().getWidth(), page.getCanvas().getHeight());

This will get page full height and width.

Use [PrintContent] (https://developer.android.com/reference/android/support/v4/print/PrintHelper.html)!

 // Get the print manager.
PrintHelper printHelper = new PrintHelper(this);

// Set the desired scale mode.
printHelper.setScaleMode(PrintHelper.SCALE_MODE_FIT);

// Get the bitmap for the ImageView's drawable.
Bitmap bitmap = ((BitmapDrawable) mImageView.getDrawable()).getBitmap();

// Print the bitmap.
printHelper.printBitmap("Print Bitmap", bitmap);

Try to convert your layout into image then set that image to PDF. read this, maybe you will get some idea. Convert view to PDF

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!