Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Printing on a laser printer

Printing on a laser printer

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Eversman
    wrote on last edited by
    #1

    Hey, When I print on a normal Printer, all the text prints fine, but when I have it print on a Laser Printer, all the text gets squahsed together, and text is wirrten over other text, it is a whole mess. Anyone know why it is doing it? Here is the code. //// Create a printer DC CPrintDialog dlg(FALSE); CDC dc; #if 0 //Show print dialog. if (dlg.DoModal() == IDCANCEL) return; dc.Attach(dlg.GetPrinterDC()); #else //Don't show print dialog. PRINTDLG prtDlg; AfxGetApp()->GetPrinterDeviceDefaults(&prtDlg); //Should check for error. dlg.m_pd.hDevMode = prtDlg.hDevMode; dlg.m_pd.hDevNames = prtDlg.hDevNames; dc.Attach(dlg.CreatePrinterDC()); #endif dc.m_bPrinting = TRUE; //// Now use the DC. //Get the page size. CRect printArea; CRect printArea1; CRect printArea2; CRect printArea3; CRect printArea4; CRect printArea5; CRect printArea6; CRect printArea7; printArea.SetRect(500, 0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing. printArea1.SetRect(700, 1500, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea2.SetRect(750, 1750, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea3.SetRect(1250, 1750, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea4.SetRect(750, 1825, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea5.SetRect(1250, 1825, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea6.SetRect(325, 250, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea7.SetRect(750, 500, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing DOCINFO docinfo; memset(&docinfo, 0, sizeof(docinfo)); docinfo.cbSize = sizeof(docinfo); docinfo.lpszDocName = _T("Edit Control Print"); dc.StartDoc(&docinfo); //Should check for error. dc.StartPage(); //Should check for error. //Draw the edit control contents. /////////////////////////// CFont font; font.CreatePointFont(480, "Arial", &dc); CFont font1; font1.CreatePointFont(280, "Arial", &dc); CString str("Text Text Text"); CString str1; CString str2("Test"); CString str3("Test"); CString str4; CString str5; CString str6("Test"); CString str7("Test"); CSize size = dc.GetTextExt

    J 1 Reply Last reply
    0
    • E Eversman

      Hey, When I print on a normal Printer, all the text prints fine, but when I have it print on a Laser Printer, all the text gets squahsed together, and text is wirrten over other text, it is a whole mess. Anyone know why it is doing it? Here is the code. //// Create a printer DC CPrintDialog dlg(FALSE); CDC dc; #if 0 //Show print dialog. if (dlg.DoModal() == IDCANCEL) return; dc.Attach(dlg.GetPrinterDC()); #else //Don't show print dialog. PRINTDLG prtDlg; AfxGetApp()->GetPrinterDeviceDefaults(&prtDlg); //Should check for error. dlg.m_pd.hDevMode = prtDlg.hDevMode; dlg.m_pd.hDevNames = prtDlg.hDevNames; dc.Attach(dlg.CreatePrinterDC()); #endif dc.m_bPrinting = TRUE; //// Now use the DC. //Get the page size. CRect printArea; CRect printArea1; CRect printArea2; CRect printArea3; CRect printArea4; CRect printArea5; CRect printArea6; CRect printArea7; printArea.SetRect(500, 0, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing. printArea1.SetRect(700, 1500, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea2.SetRect(750, 1750, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea3.SetRect(1250, 1750, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea4.SetRect(750, 1825, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea5.SetRect(1250, 1825, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea6.SetRect(325, 250, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing printArea7.SetRect(750, 500, dc.GetDeviceCaps(HORZRES), dc.GetDeviceCaps(VERTRES)); //Start printing DOCINFO docinfo; memset(&docinfo, 0, sizeof(docinfo)); docinfo.cbSize = sizeof(docinfo); docinfo.lpszDocName = _T("Edit Control Print"); dc.StartDoc(&docinfo); //Should check for error. dc.StartPage(); //Should check for error. //Draw the edit control contents. /////////////////////////// CFont font; font.CreatePointFont(480, "Arial", &dc); CFont font1; font1.CreatePointFont(280, "Arial", &dc); CString str("Text Text Text"); CString str1; CString str2("Test"); CString str3("Test"); CString str4; CString str5; CString str6("Test"); CString str7("Test"); CSize size = dc.GetTextExt

      J Offline
      J Offline
      Johan Rosengren
      wrote on last edited by
      #2

      You must take differences in printer resolution into consideration. Your printing rects have hardcoded coordinates, which is bad, bad, bad. To get the resolution for a single inch of the printer, call dc.GetDeviceCaps( LOGPIXELSX/LOGPIXELSY);. Use values based on the return for the start coordinates in your SetRect-calls.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups