Click here to Skip to main content
15,920,217 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can i change the page width and height updating the DEVMODE of a printer.
Posted

You must fill the devmode with desired paper sizes on calls to PrintDlg() or CreateDC(). I think there's no way to modify devmode after this.

In case if you are printing in RAW (TEXT) mode , you can pass in the devmode to OpenPrinter() and proceed to StartDocPrinter -> StartPagePrinter

Wonder why you wish to change page sizes in the middle of printing?
 
Share this answer
 
To change DEVMODE settings during a print job (such as different paper bin, paper size, etc), you need to recreate the DC, passing a different DEVMODE struct. If using MFC, below is a snippet that may give you some ideas:

memcpy(pNewDevMode,pCurDevMode,pCurDevMode->dmSize+pCurDevMode->dmDriverExtra);
pNewDevMode->dmFields      = pDevMode->dmFields;
pNewDevMode->dmOrientation = pDevMode->dmOrientation;
pNewDevMode->dmPaperSize   = pDevMode->dmPaperSize;
pNewDevMode->dmPaperLength = pDevMode->dmPaperLength;
pNewDevMode->dmPaperWidth  = pDevMode->dmPaperWidth;
pNewDevMode->dmScale       = pDevMode->dmScale;
pNewDevMode->dmCopies      = pInfo->m_pPD->GetCopies();
pNewDevMode->dmDefaultSource = pDevMode->dmDefaultSource;
CString cDevice = pInfo->m_pPD->GetDeviceName();
CString cDriver = pInfo->m_pPD->GetDriverName();
CString cPort   = pInfo->m_pPD->GetPortName();
HDC hDC = ::CreateDC((LPCSTR)((const char *)cDriver),
                     (LPCSTR)((const char *)cDevice),
                     (LPCSTR)((const char *)cPort),
                     <big>pNewDevMode</big>);
if (hDC)
  {
    pDC->EndDoc();
    HDC hOldDC = pDC->Detach();
    if (hOldDC)
      ::DeleteDC(hOldDC);
    pDC->Attach(hDC);
    pDC->SetAbortProc(PrintAbortProc);
    DOCINFO docInfo;
    ZeroMemory(&docInfo, sizeof(DOCINFO));
    docInfo.cbSize = sizeof(DOCINFO);
    char caName[31];
    strcpy(caName,((const char *)pDoc->GetTitle().Left(30)));
    docInfo.lpszDocName = (LPCSTR)caName;
    docInfo.lpszOutput = NULL;
    if (pDC->StartDoc(&docInfo) == SP_ERROR)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900