Solved

Paper size in Printing

Posted on 1998-05-07
8
819 Views
Last Modified: 2013-11-20
How to print in WINNT to folder paper, which size isn't
offer in Printing setup dialog. Is any way how  to add a chois custom size of  paper to Printing Setup dialog?

I tried change paper size after calling Print dialog by
following code:

LPDEVMODE devMode = pInfo->m_pPD->GetDevMode();
devMode->dmFields|=DM_PAPERLENGTH|DM_PAPERWIDTH|DM_PAPERSIZE;
devMode->dmPaperSize=0;
devMode->dmPaperLength=myLength();
devMode->dmPaperWidth=myWidth();
CPrintDialog * pPD = pInfo->m_pPD;
CDC *dc= new CDC();
dc->Attach(pPD->m_pd.hDC);
dc->ResetDC(devMode);
long height = dc->GetDeviceCaps(VERTSIZE)  ;

The result is that height is apropriate to A4 paper size, not
to my size.

                       Thank You    Ivan



0
Comment
Question by:ivano
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 

Author Comment

by:ivano
ID: 1308142
Edited text of question
0
 

Author Comment

by:ivano
ID: 1308143
Adjusted points to 200
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308144
I'd try this in your winapp.  Call this before you do any printing (eg. in your InitInstance) to set the size you want.  I use this technique for changing the paper orientation to landscape.

void CMyWinApp::SetSize(int width, int length) {
  // Get default printer settings.
  CPrintDialog dlg(false);
  if (GetPrinterDeviceDefaults(&dlg.m_pd)) {
    // Lock memory handle.
    LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(m_hDevMode);
    // Change printer settings in here.
    if (pDevMode) {
      pDevMode->dmFields |= DM_PAPERLENGTH|DM_PAPERWIDTH|DM_PAPERSIZE;
      pDevMode->dmPaperSize=0;
      pDevMode->dmPaperLength=length;
      pDevMode->dmPaperWidth=width;
    }
    // Unlock memory handle.
    ::GlobalUnlock(m_hDevMode);
  }
}

0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:ivano
ID: 1308145
The problem isn't where to set the paper size. When I experiment with code written in my question, I was succesful only when I used some paper size, which is offered in print dialog.

For examle code  
devMode->dmFields|=DM_PAPERSIZE;
devMode->dmPaperSize=DM_PAPERQUATRO;
work OK.

So I thing, that place the code in InitInstance isn't solution.
I doubt whether printer driver allowed other paper size, then is offered in print dialog.
0
 
LVL 10

Expert Comment

by:RONSLOW
ID: 1308146
The dmPaperSize member of the DEVMODE structure is documented incorrectly. The documentation states that the dmPaperSize member may be set to zero if the length and width of the paper are specified by the dmPaperLength and dmPaperWidth members, respectively. However, the correct value to use for user-defined paper sizes is DMPAPER_USER.

0
 

Author Comment

by:ivano
ID: 1308147
Even if I used DMPAPER_USER, I can't change the paper size.
I tried to do it in OnPreparePrinting. I found  following:

When I used next  code, value of variable heigh isn't appropriate to my  requested paper size, but value is appropriate to A4 . But what is interesting, when I replace the  row
           devMode->dmPaperSize=DMPAPER_USER
by for example
           devMode->dmPaperSize=DMPAPER_QUARTO;
the value heigh is appropriate to choosen paper size, printing is done OK, including pagination.
Whenever I set dmPaperSize to any predefined paper size  result is success.
           Is it  possible that in WINNT is possible to print only on paper size, which are predefined? I can't explain this behavior to myself.
                  Thank's for any advice

BOOL CTReportView::OnPreparePrinting(CPrintInfo* pInfo)
{
      pInfo->m_pPD->m_pd.Flags |= D_HIDEPRINTTOFILE | PD_NOPAGENUMS;
      CPrintDialog * pPD = pInfo->m_pPD;
      BOOL ret = DoPreparePrinting(pInfo);
      LPDEVMODE devMode = pInfo->m_pPD->GetDevMode();
devMode->dmFields|=DM_PAPERLENGTH|DM_PAPERWIDTH|DM_PAPERSIZE;
      devMode->dmPaperSize=DMPAPER_USER;
      devMode->dmPaperLength=1016;
      devMode->dmPaperWidth=2100;

      // DC apropiate to setting made in print dialog
      ::DeleteDC(pPD->m_pd.hDC); // deleting  DC apropiate to setting made in print dialog

      // Creating DC appropriate to my requirement
                 pPD->m_pd.hDC=pPD->CreatePrinterDC();
      dc->Attach(pPD->m_pd.hDC);
      heigh = dc->GetDeviceCaps(VERTSIZE) ;
                return TRUE;
}//CTReportView::OnPreparePrinting
0
 
LVL 10

Accepted Solution

by:
RONSLOW earned 300 total points
ID: 1308148
Have you tried setting the paper size in the way I suggested earlier, but with the DMPAPER_USER instead of 0.  ie:

void CMyWinApp::SetSize(int width, int length) {
  // Get default printer settings.
  CPrintDialog dlg(false);
  if (GetPrinterDeviceDefaults(&dlg.m_pd)) {
    // Lock memory handle.
    LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(m_hDevMode);
    // Change printer settings in here.
    if (pDevMode) {
      pDevMode->dmFields |= DM_PAPERLENGTH|DM_PAPERWIDTH|DM_PAPERSIZE;
      pDevMode->dmPaperSize=DMPAPER_USER;
      pDevMode->dmPaperLength=length;
      pDevMode->dmPaperWidth=width;
    }
    // Unlock memory handle.
    ::GlobalUnlock(m_hDevMode);
  }
}

And then calling this from your InitInstance (say) to set up the required length.  Does this work?

If it does, then the problem may be in how and when your are making your change.  If it does not work, then it may be some limitation of your printer driver.

0
 

Author Comment

by:ivano
ID: 1308149
I find out, that code you suggest to me is running in  WIN95 but not int WINNT. So that means, that driver in WINNT doesn't support users paper size.

        Thank you for your advices.


0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 87
Hibernate methods 2 87
bigDiff challenge 17 142
My project did see openJDK that I installed. What could be the problem 7 169
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question