Generate and print a PDF with specific size in Android

五迷三道 提交于 2019-12-05 11:26:55

I know it's a bit later. However, I have made my custom size with this approach : ( widthMils: 5800, heightMils: 40000). The unit of measurement is: one thousandth of an inch.

private PrintAttributes getDefaultPrintAttrs() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return null;

    PrintAttributes.MediaSize customSize = new 
    PrintAttributes.MediaSize("COIL", "COIL", 5800,40000);
    customSize.asPortrait();

    return new PrintAttributes.Builder()
            .setMediaSize(customSize)
            .setResolution(new PrintAttributes.Resolution("RESOLUTION_ID", "RESOLUTION_ID", 600, 600))
            .setMinMargins(PrintAttributes.Margins.NO_MARGINS)
            .build();

}

Just so you don't break your head over it, like I did, check out this bug report: https://code.google.com/p/android/issues/detail?id=180405

Considering this bug report, I'd say it's a problem with the android printing interface and you can't really set any defaults using PrintAttributes, well at least not until android N.

If you find/found a workaround, please let me know :)

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