• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps PDF Printing not accepting orientation

I have a strange issue with trying to print to PDF or even to a wireless printer in that I cannot get the orientation to change to landscape. I use the following code to set landscape mode as the MediaSize.

PrintAttributes attrib = new PrintAttributes.Builder()
.setMinMargins(new PrintAttributes.Margins(0,0,0,0))

printManager.print("Document", printAdapter, attrib);

If I breakpoint at the last time and check attrib, it is correct with landscape being passed into the print function.but when OnLayout is called after this, checking newAttributes passed into the function shows the orientation as portrait and not the select landscape. The only fix is to manually select this in the preview. Not ideal for the user to have to do this each time.

Now, here's the strange part. I have 2 systems with different LCD's. A 7 inch one with default resolution of 800x1280 in portrait mode timing but I change this to landscape when Android boots up. It is fixed in this landscape orientation. The second system is an 11.6" 1920x1080 with landscape mode timing. It too is fixed in this landscape mode and cannot rotate.

If I run the same application on the device with the 1920x1080 display, the printout preview is in landscape as expected but if I change the code to force portrait as a test, the preview remains in landscape mode and I have to manually select this to the correct orientation.

Printing without changing the orientation to the correct one causes the wrong orientation to be printed.

I've checked the source code for PrintDocumentAdapter and the setting for landscape should be working.

Why is the landscape/portrait mode not changing with the above code? All searches online point to this as the correct way to change the orientation but it just doesn't work. I need a solution as having the user change this each time is not the ideal way to do this.


We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.