Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the default "Portrait Orientation" to Landscape in Android Print Framework?

Is there a way to change default portrait preview to landscape in print framework?

I have tried below -

PrintAttributes attrib = new PrintAttributes.Builder()
.setMediaSize(PrintAttributes.MediaSize.NA_LETTER.asLandscape())
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
. build();

and also tried below -

PrintAttributes attrib = new PrintAttributes.Builder()
.setMediaSize(PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE)
.setMinMargins(PrintAttributes.Margins.NO_MARGINS)
. build();

I've noticed that it doesn't change the page orientation to Landscape

print settings

In above print setting dialog if I do change the orientation to landscape then and only then the print preview page changes orientation to Landscape. Can this be done programmatically? I want default preview in Landscape.

like image 506
kevz Avatar asked Oct 14 '16 12:10

kevz


People also ask

How do I change my default print to landscape?

Find your printer in the Devices and Printers window and right-click the icon with your mouse. In the menu that appears, select Printing Preferences and find the option for Orientation in the preferences window. Change the option to Landscape to set the printer to Landscape mode as a default.

Why is my printer printing landscape when set to portrait?

Program Settings Although the printer might be correctly configured to print in Portrait mode, the program itself might be configured to print in Landscape mode. These settings are typically adjusted by locating a Page Setup or Page Layout menu and then looking for Orientation.


1 Answers

I used below Code:

PrintManager printManager = (PrintManager) this.getSystemService(Context.PRINT_SERVICE);
    String jobName = this.getString(R.string.app_name) + " Document";

    PrintAttributes attrib = new PrintAttributes.Builder()
            .setMediaSize(PrintAttributes.MediaSize.UNKNOWN_LANDSCAPE)
            . build();

    printManager.print(jobName, pda, attrib);

My Result:

enter image description here

like image 143
Md. Zakir Hossain Avatar answered Sep 17 '22 09:09

Md. Zakir Hossain