Android Printing with custom paper size

4.9k Views Asked by At

I'm using receipt paper (4.2" x 11") for printing my invoice from Android Device through Wifi. However, It always prints blank paper. But, If I use A4 paper, it prints the content on the paper.

So I modified my print code as following,

PrintManager printManager = (PrintManager) getSystemService(Context.PRINT_SERVICE);
        String jobName = " Document";
        PrintAttributes.Builder builder = new PrintAttributes.Builder();
        PrintAttributes.MediaSize custom = new PrintAttributes.MediaSize("10 Envelope" , "Custom", 4200,11000);
        builder.setMediaSize( custom );
        PrintJob printJob = printManager.print(jobName, pda,
                builder.build());

But android is not showing this option in the print menu. It shows only the default paper size.

Screenshot of Paper size List

I even tried , PrintAttributes.MediaSize.JPN_YOU4 which is the closest size of my paper, It doesn't show it as well. Please give me any suggestions.

1

There are 1 best solutions below

0
On

The problem is probably the reported in this issue: https://issuetracker.google.com/issues/37054219

And unless you can use Android N, when it was fixed, you are out of luck. I don't know any workaround to this situation.