• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 593
  • Last Modified:

Print Preview

This is my first time creating a SDI project.
I am having trouble in that I am just writing text to the screen.  The text looks great on the screen but the Print preview looks compressed and illegible.

I am following the directions from
Appendix C of Sams Teach Yourself VC++6
So, I must be doing something wrong because it doesn't look so great when I print it.

using Win98

Does anybody see anything wrong?

Thanks for your help.
Vida


void CPrintItView::OnDraw(CDC* pDC)
{
     CPrintItDoc* pDoc = GetDocument();
     ASSERT_VALID(pDoc);
     // TODO: add draw code for native data here
     int left_margin = 20;
     int y = 15;//starting y position
     int line_offset = 20;
      //Declare a client rectangle
     CRect rcClient;
     GetClientRect(&rcClient);

     if(pDC->IsPrinting())//returns true if printing
     {
     //Find the Print width : Window width ratio
          double dWidthRatio=(double)m_rcPrintRect.Width()/(double)rcClient.Width();
     //Find the Print height : Window Height ration
          double dHeightRatio=(double)m_rcPrintRect.Height()/(double)rcClient.Height();
     //Calculate the device's aspect ratio
          double dAspect=(double)pDC->GetDeviceCaps(ASPECTX)/(double)pDC->GetDeviceCaps(ASPECTY);
     //Find the new relative height
          int nHeight=(int)(rcClient.Height()*dWidthRatio*dAspect);
     //Find the new relative width
          int nWidth=(int)(rcClient.Width()*dHeightRatio*(1.0/dAspect));
     //Set the whole rectangle
          rcClient = m_rcPrintRect;

     //Determine the best fit across or down the page
          if(nHeight > nWidth)
          {
               //Down is best, so adjust the width
               rcClient.BottomRight().x=m_rcPrintRect.TopLeft().x + nWidth;
          }
          else
          {
               //Across is best, so adjust the height
               rcClient.BottomRight().y=m_rcPrintRect.TopLeft().y + nHeight;
          }
     
     }


     // Draw Text

     pDC->TextOut(left_margin,y,"Line one text");
     y+=line_offset;
     pDC->TextOut(left_margin,y,"Line two text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line three text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line four text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line five text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line six text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line seven text");
     y+=line_offset;
     pDC->TextOut(left_margin,y++,"Line eight text");
     y+=line_offset;
}
0
vpomona
Asked:
vpomona
1 Solution
 
jackrabbit22Commented:
First thing: Since you're outputting text, would it be a better solution for you to use CEditView or CRichEditView and their built in printing features?

Secondly:
I assume that you're using MM_TEXT mapping mode, which means that each logical drawing unit (the units used in drawing functions like TextOut, LineTo, etc.) is equal to one pixel on the device you're outputing to.  The problem is that each device (screen vs printer) can have a different # of pixels per inch. (resolution)

For the screen, it's usually close to 100 pixels per inch. (I think it's 96?)  For a printer, it's usually 150, 300 or 600 pixels per inch.  This means that the printer output will be 1.5x, 3x or 6x smaller respectively.

Suggestions:

- Read up on and using a different mapping mode.  You'll probably find MM_LOENGLISH or MM_ANISOTROPIC a good solution for your problem.

- For samples, check out the printing articles at
http://www.codeguru.com/printing/index.shtml and
http://www.codeproject.com/printing/
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now