1. Are you ready for the Galaxy S20? Here is everything we know so far!

PDF Printing not accepting orientation

Discussion in 'Android Development' started by David McLaughlin, Sep 13, 2020.

  1. David McLaughlin

    Thread Starter

    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))
    .setMediaSize(PrintAttributes.MediaSize.NA_LETTER.asLandscape())
    .setColorMode(PrintAttributes.COLOR_MODE_COLOR)
    .build();

    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.
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...