Change Printing Orientation during middle of print job.
Hi experts, I know there is tons of stuff about this on web but cant get anything to work!
I am using VC++ MFC unmanaged. I would like to change the orientation of my pages as the print job goes on. Users have the option to have a page landscape or portrait when they work and obviously this needs to be reflected when they print. How can i change printining orientation at run time.
Call it from any place of the program:
((CMyApp*)AfxGetApp())->SetLandscapeMode(TRUE); // or false
I am not sure that this will work in the middle of printing, but you can try. If this will not work, you need to make number of print jobs, for example:
Job 1 - portrait, page 1
Job 2 - landscape, page 2
...
User executes command "Print", and internally program runs number of print jobs.
0
wdhoughAuthor Commented:
Tried you first choice and as we both suspected it didnt work. I think you can really only take that approach before you decide to print.
The second point is interesting, remember I can be printing to any sort of printer including Adobe Distiller, which in the above example would produce two files. I dont think this approach is the solution
um, well i give them the option to work portrait or landscape. You get this MS word. I have just taken it a little further and allowed them to have page 1 portrait and page 2 landscape, instead of both pages either portrait or landscape.
the only problem at the moment is i cant give them this option for printing.
/* Start by opening the printer */
if (!OpenPrinter(pDevice, &hPrinter, NULL))
return NULL;
/*
* Step 1:
* Allocate a buffer of the correct size.
*/
dwNeeded = DocumentProperties(hWnd,
hPrinter, /* handle to our printer */
pDevice, /* Name of the printer */
NULL, /* Asking for size so */
NULL, /* these are not used. */
0); /* Zero returns buffer size. */
pDevMode = (LPDEVMODE)malloc(dwNeeded);
/*
* Step 2:
* Get the default DevMode for the printer and
* modify it for our needs.
*/
dwRet = DocumentProperties(hWnd,
hPrinter,
pDevice,
pDevMode, /* The address of the buffer to fill. */
NULL, /* Not using the input buffer. */
DM_OUT_BUFFER); /* Have the output buffer filled. */
if (dwRet != IDOK)
{
/* if failure, cleanup and return failure */
free(pDevMode);
ClosePrinter(hPrinter);
return NULL;
}
/*
* Make changes to the DevMode which are supported.
*/
if (pDevMode->dmFields & DM_ORIENTATION)
{
/* if the printer supports paper orientation, set it*/
pDevMode->dmOrientation = DMORIENT_LANDSCAPE;
}
/*
* Step 3:
* Merge the new settings with the old.
* This gives the driver a chance to update any private
* portions of the DevMode structure.
*/
dwRet = DocumentProperties(hWnd,
hPrinter,
pDevice,
pDevMode, /* Reuse our buffer for output. */
pDevMode, /* Pass the driver our changes. */
DM_IN_BUFFER | /* Commands to Merge our changes and */
DM_OUT_BUFFER); /* write the result. */
/* Done with the printer */
ClosePrinter(hPrinter);
if (dwRet != IDOK)
{
/* if failure, cleanup and return failure */
free(pDevMode);
return NULL;
}
/* return the modified DevMode structure */
return pDevMode;
}
-MAHESH
0
wdhoughAuthor Commented:
Mahesh,
Thanks for your help buddy, this seems to do the trick. The only thing I will add to this is i seemed to need to put the line below in as well, as the paper size/type was being lost.
pDevMode->dmPaperSize = my_paper_id;
I had to put this at the same point that i changed the orientation.
Thanks for your help
0
Question has a verified solution.
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
See void CMyApp::SetLandscapeMode()
void CMyApp::SetLandscapeMode(B
Call it from any place of the program:
((CMyApp*)AfxGetApp())->Se
I am not sure that this will work in the middle of printing, but you can try. If this will not work, you need to make number of print jobs, for example:
Job 1 - portrait, page 1
Job 2 - landscape, page 2
...
User executes command "Print", and internally program runs number of print jobs.