Printing in Document-View architecture
-
The number of pages to print from my document can vary from 4 to 10 pages. The printwork consist in a cover page as first page followed by 3 to 9 data pages. Each data page has a header and footer line. I correct the m_rectDraw in the pInfo structure for this header and footer line as indicated in the Scribble tutorial or by Prosise and Kruglinsky in their books. Printing is done in mapping mode MM_TEXT. With my "old" HP600 inktjet printer printing works fine and even the print preview works fine. But printing goes wrong on a HP Laserwriter, HP 1600CM inktjet printer and Lexmark OptraE laser printer on starting the 3rd page this is the 2nd data page,if the document has more than 7 data pages in a lane. How can I solve this problem ?
-
The number of pages to print from my document can vary from 4 to 10 pages. The printwork consist in a cover page as first page followed by 3 to 9 data pages. Each data page has a header and footer line. I correct the m_rectDraw in the pInfo structure for this header and footer line as indicated in the Scribble tutorial or by Prosise and Kruglinsky in their books. Printing is done in mapping mode MM_TEXT. With my "old" HP600 inktjet printer printing works fine and even the print preview works fine. But printing goes wrong on a HP Laserwriter, HP 1600CM inktjet printer and Lexmark OptraE laser printer on starting the 3rd page this is the 2nd data page,if the document has more than 7 data pages in a lane. How can I solve this problem ?
Here is some code I used for printing multi-page documents. It doesn't use the m_rectDraw for calculating the number of pages. It gets a printer device context from the current selected printer. Then calls GetDeviceCaps(HORZRES) and GetDeviceCaps(VERTRES) to get the printer page size. BOOL CInfoWindowView::OnPreparePrinting(CPrintInfo* pInfo) { pInfo->SetMaxPage(GetNumberOfPrintPages(pInfo)); // default preparation return DoPreparePrinting(pInfo); } WORD CInfoWindowView::GetNumberOfPrintPages(CPrintInfo* /*pInfo*/) { PRINTDLG PrtDlg; HDC hDC; //// Create a printer DC if(!AfxGetApp()->GetPrinterDeviceDefaults(&PrtDlg)) { TRACE("No default printer.\n"); // use screen DC for calculations // It's OK to do this because this CDC will not be used for any // output. hDC = ::CreateDC("display",NULL,NULL,NULL); } else { CPrintDialog dlg(FALSE); dlg.m_pd.hDevMode = PrtDlg.hDevMode; dlg.m_pd.hDevNames = PrtDlg.hDevNames; hDC = dlg.CreatePrinterDC(); } CDC* pDC = CDC::FromHandle(hDC); // This is a printer DC, so set m_bPrinting // this is necessary so CScrollView::OnPrepareDC won't modify the // ViewportOrg, and cause LPtoDP to return an inappropriate result. pDC->m_bPrinting = TRUE; //// Calculate print stuff. CFont font; CFont *pOldFont; CSize size; CInfoWindowDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); //Setup the font. font.CreatePointFont(INFO_WINDOW_FONT_SIZE, INFO_WINDOW_FONT_FACE, pDC); pOldFont = pDC->SelectObject(&font); size = pDC->GetTextExtent("X"); //// Get the printer page sizeS. LONG lHeaderHeight; LONG lFooterHeight; LONG lPageWidth, lPageHeight; lPageWidth = pDC->GetDeviceCaps(HORZRES); lPageHeight = pDC->GetDeviceCaps(VERTRES); //Header height is 4 lines. lHeaderHeight = size.cy * 4; //Footer height is 2 lines. lFooterHeight = size.cy * 2; //Set header, page, and footer rects. m_rectPrintHeader.SetRect(0, 0, lPageWidth, lHeaderHeight); //Print area for info. m_rectPrintPage.SetRect(0, m_rectPrintHeader.bottom, lPageWidth, m_rectPrintHeader.bottom + (lPageHeight - (lHeaderHeight + lFooterHeight))); //Footer area. m_rectPrintFooter.SetRect(0, m_rectPrintPage.bottom, lPageWidth, lPageHeight); (size.cy * 1)); //Calculate other stuff. m_wLinesPerPrinterPage = WORD(m_rectPrintPage.Height() / size.cy); m_wPrinterPages = (WORD)ceil((double)pDoc->GetNumberOfTextLines() / m_wLinesPerPrinterPage); m_wPrinterPag
-
The number of pages to print from my document can vary from 4 to 10 pages. The printwork consist in a cover page as first page followed by 3 to 9 data pages. Each data page has a header and footer line. I correct the m_rectDraw in the pInfo structure for this header and footer line as indicated in the Scribble tutorial or by Prosise and Kruglinsky in their books. Printing is done in mapping mode MM_TEXT. With my "old" HP600 inktjet printer printing works fine and even the print preview works fine. But printing goes wrong on a HP Laserwriter, HP 1600CM inktjet printer and Lexmark OptraE laser printer on starting the 3rd page this is the 2nd data page,if the document has more than 7 data pages in a lane. How can I solve this problem ?
Here you will find how I finally solved the problem. I thank Jonathan for his kind suggestion not to rely on the m_rectDraw in the CInfo structure. But even this does not solve the problem but it helps to have more consistent printwork between different printers. I found a go around the problem by splitting the document in a view with, in my case, three sections as to keep the total number of pages under 8 pages for wich the standard MFC print functions work fine.