How to Change Print Orientation in MFC

There is no big science to it, but thanks to a “bad choice of title”, the appropriate MSDN-KB-HOWTO article is not easy to find. So, here’s a link:

MSDN KB 126897: How to Change Default Printer Settings in an MFC Application

The above link takes you directly to the code snippet that sets print orientation to landscape; to change the orientation to portrait, you only need to change the DMORIENT_LANDSCAPE to DMORIENT_PORTRAIT; of course, the easiest way is to change the function to allow user to choose the orientation.

Note: The presented code, of course, also changes the orientation of the print preview.

To use the above code, simply surround your printing (or print preview) code with (provided you changed the function to accept bool to choose orientation, and to return previous setting):

CMyApp* app = (CMyApp*) ::AfxGetApp();
bool old_po = app->SetPrintOrientation(*your choice of orientation*);
// printing (or print preview) code comes here
app->SetPrintOrientation(old_po);

Note: So far, I didn’t manage to find a way to change the print orientation for individual pages; seems like you have to print portrait and landscape oriented pages in separate print jobs (?).

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s