ivano
asked on
Paper size in Printing
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_PAPE RLENGTH|DM _PAPERWIDT H|DM_PAPER SIZE;
devMode->dmPaperSize=0;
devMode->dmPaperLength=myL ength();
devMode->dmPaperWidth=myWi dth();
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
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_PAPE
devMode->dmPaperSize=0;
devMode->dmPaperLength=myL
devMode->dmPaperWidth=myWi
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
ASKER
Adjusted points to 200
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_PAPERWID TH|DM_PAPE RSIZE;
pDevMode->dmPaperSize=0;
pDevMode->dmPaperLength=le ngth;
pDevMode->dmPaperWidth=wid th;
}
// Unlock memory handle.
::GlobalUnlock(m_hDevMode) ;
}
}
void CMyWinApp::SetSize(int width, int length) {
// Get default printer settings.
CPrintDialog dlg(false);
if (GetPrinterDeviceDefaults(
// Lock memory handle.
LPDEVMODE pDevMode = (LPDEVMODE)::GlobalLock(m_
// Change printer settings in here.
if (pDevMode) {
pDevMode->dmFields |= DM_PAPERLENGTH|DM_PAPERWID
pDevMode->dmPaperSize=0;
pDevMode->dmPaperLength=le
pDevMode->dmPaperWidth=wid
}
// Unlock memory handle.
::GlobalUnlock(m_hDevMode)
}
}
ASKER
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_PAPE RSIZE;
devMode->dmPaperSize=DM_PA PERQUATRO;
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.
For examle code
devMode->dmFields|=DM_PAPE
devMode->dmPaperSize=DM_PA
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.
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.
ASKER
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=DMPAP ER_USER
by for example
devMode->dmPaperSize=DMPAP ER_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::OnPreparePri nting(CPri ntInfo* 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_PAPE RLENGTH|DM _PAPERWIDT H|DM_PAPER SIZE;
devMode->dmPaperSize=DMPAP ER_USER;
devMode->dmPaperLength=101 6;
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->CreateP rinterDC() ;
dc->Attach(pPD->m_pd.hDC);
heigh = dc->GetDeviceCaps(VERTSIZE ) ;
return TRUE;
}//CTReportView::OnPrepare Printing
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=DMPAP
by for example
devMode->dmPaperSize=DMPAP
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::OnPreparePri
{
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_PAPE
devMode->dmPaperSize=DMPAP
devMode->dmPaperLength=101
devMode->dmPaperWidth=2100
// DC apropiate to setting made in print dialog
::DeleteDC(pPD->m_pd.hDC);
// Creating DC appropriate to my requirement
pPD->m_pd.hDC=pPD->CreateP
dc->Attach(pPD->m_pd.hDC);
heigh = dc->GetDeviceCaps(VERTSIZE
return TRUE;
}//CTReportView::OnPrepare
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
Thank you for your advices.
ASKER