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
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Printer Control

Printer Control

Scheduled Pinned Locked Moved C / C++ / MFC
databaselearning
18 Posts 3 Posters 1 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.
  • J Jochen Arndt

    You are right. I missed that.

    L Offline
    L Offline
    Lost User
    wrote on last edited by
    #8

    That's OK, I missed the XP bit. :)

    B 1 Reply Last reply
    0
    • L Lost User

      That's OK, I missed the XP bit. :)

      B Offline
      B Offline
      Bram van Kampen
      wrote on last edited by
      #9

      Well, I Got it to Produce the XPS File without Complaining. However, The XPS Reader complains it Cannot Read the XPS File. Both in Win7 and Win 10. The Text I propose to Print is as Follows:- It Renders in NotePad as:

       Finding Old Orders in the Shop     
      

      Printed by on 01 09 16 - 23:40:14

      Customer:-
      TONY LOUGHLIN

      If The Item(s) are Found you should
      Update the Computer Record, and
      Destroy this Page!
      Otherwise Inform Management of the
      Discrepancies, by Returning this Page
      Marked Up Accordingly!

      Order Nr 214058

      Received on: 27/07/12 - 13:18:21

      Not Confirmed Present since Completion

      Qty Description Amount
      1 lb Wash +Dry £11.00
      ========
      Total For Order £11.00
      Due for This Order £11.00

      Packaging:- -1Wb

      ========================================

              Actually Found:-            
      

      Hangers Pastics Flatpacks WashBags
      +---+ +---+ +---+ +---+
      | | | | | | | |
      | | | | | | | |
      | | | | | | | |
      +---+ +---+ +---+ +---+

      ========================================

      The XPS File I got was,in Binary. There is nothing wrong with the way I present My Data, Somehow the Printer will not Digest it. I Need to get to the bottom of this, and everybodies help is much appreciated. If Needed, will show the Code! Regards, :) :) :)

      Bram van Kampen

      L 1 Reply Last reply
      0
      • B Bram van Kampen

        Well, I Got it to Produce the XPS File without Complaining. However, The XPS Reader complains it Cannot Read the XPS File. Both in Win7 and Win 10. The Text I propose to Print is as Follows:- It Renders in NotePad as:

         Finding Old Orders in the Shop     
        

        Printed by on 01 09 16 - 23:40:14

        Customer:-
        TONY LOUGHLIN

        If The Item(s) are Found you should
        Update the Computer Record, and
        Destroy this Page!
        Otherwise Inform Management of the
        Discrepancies, by Returning this Page
        Marked Up Accordingly!

        Order Nr 214058

        Received on: 27/07/12 - 13:18:21

        Not Confirmed Present since Completion

        Qty Description Amount
        1 lb Wash +Dry £11.00
        ========
        Total For Order £11.00
        Due for This Order £11.00

        Packaging:- -1Wb

        ========================================

                Actually Found:-            
        

        Hangers Pastics Flatpacks WashBags
        +---+ +---+ +---+ +---+
        | | | | | | | |
        | | | | | | | |
        | | | | | | | |
        +---+ +---+ +---+ +---+

        ========================================

        The XPS File I got was,in Binary. There is nothing wrong with the way I present My Data, Somehow the Printer will not Digest it. I Need to get to the bottom of this, and everybodies help is much appreciated. If Needed, will show the Code! Regards, :) :) :)

        Bram van Kampen

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #10

        Bram van Kampen wrote:

        The XPS File I got was,in Binary.

        As you would expect, since it also includes formatting information about the content. I have used this to test printing in my applications, and never had a problem. I guess you need to look at your actual printing code.

        B 1 Reply Last reply
        0
        • L Lost User

          Bram van Kampen wrote:

          The XPS File I got was,in Binary.

          As you would expect, since it also includes formatting information about the content. I have used this to test printing in my applications, and never had a problem. I guess you need to look at your actual printing code.

          B Offline
          B Offline
          Bram van Kampen
          wrote on last edited by
          #11

          Well, The Binary I get refuses to open. Here is my Printing Code:-

          ///////////////////////////////////////////////////////////////////////////////////
          //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
          //
          // PRINTING!!
          ///////////////////////////////////////////////////////////////////////////////////

          // OnClick the Print Button
          void CConfirmOrdersStep1Dlg::OnPrint()
          {
          if(CreateViewForPrinting()==false){
          AfxMessageBox("No Orders have been Marked for Printing");
          return;
          }
          CDC dc;
          CPrintDialog printDlg(FALSE);

          if (printDlg.DoModal() == IDCANCEL)     // Get printer settings from user
              return;
          
          dc.Attach(printDlg.GetPrinterDC());     // Get and attach a printer DC
          dc.m\_bPrinting = TRUE;
          
          CString strTitle="Old Orders";                       // Get the application title
          //strTitle.LoadString(AFX\_IDS\_APP\_TITLE);
          

          // strTitle.Format("Date:Confirming Old Orders By:- %s-%s", UserName,Date);

          DOCINFO di;                             // Initialise print document details
          memset(&di, 0,sizeof (DOCINFO));
          di.cbSize = sizeof (DOCINFO);
          di.lpszDocName = strTitle;
          
          BOOL bPrintingOK = dc.StartDoc(&di);    // Begin a new print job
          
          // Get the printing extents and store in the m\_rectDraw field of a 
          // CPrintInfo object
          CPrintInfo Info;
          Info.m\_rectDraw.SetRect(0,0, 
                                  dc.GetDeviceCaps(HORZRES), 
                                  dc.GetDeviceCaps(VERTRES));
          
          OnBeginPrinting(&dc, &Info);            // Call your "Init printing" function
          
          // Now, Print every Page!
          UINT page;
          for (page=Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK;page++){
          
              dc.StartPage();                     // begin new page
              Info.m\_nCurPage = page;
              PrintPage(&dc, &Info);                // Call your "Print page" function
              bPrintingOK = (dc.EndPage() > 0);   // end page
          }
          OnEndPrinting(&dc, &Info);              // Call your "Clean up" function
          
          if (bPrintingOK)
              dc.EndDoc();                        // end a print job
          else
              dc.AbortDoc();                      // abort job.
          
          dc.DeleteDC();                          // delete the printer DC	
          

          }

          // As from Chris Mauder.
          // Instead of Global I made it a member
          //
          // m_pView (Type COrderPageView) contains a list of PageFragments
          // Th

          B L 3 Replies Last reply
          0
          • B Bram van Kampen

            Well, The Binary I get refuses to open. Here is my Printing Code:-

            ///////////////////////////////////////////////////////////////////////////////////
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            //
            // PRINTING!!
            ///////////////////////////////////////////////////////////////////////////////////

            // OnClick the Print Button
            void CConfirmOrdersStep1Dlg::OnPrint()
            {
            if(CreateViewForPrinting()==false){
            AfxMessageBox("No Orders have been Marked for Printing");
            return;
            }
            CDC dc;
            CPrintDialog printDlg(FALSE);

            if (printDlg.DoModal() == IDCANCEL)     // Get printer settings from user
                return;
            
            dc.Attach(printDlg.GetPrinterDC());     // Get and attach a printer DC
            dc.m\_bPrinting = TRUE;
            
            CString strTitle="Old Orders";                       // Get the application title
            //strTitle.LoadString(AFX\_IDS\_APP\_TITLE);
            

            // strTitle.Format("Date:Confirming Old Orders By:- %s-%s", UserName,Date);

            DOCINFO di;                             // Initialise print document details
            memset(&di, 0,sizeof (DOCINFO));
            di.cbSize = sizeof (DOCINFO);
            di.lpszDocName = strTitle;
            
            BOOL bPrintingOK = dc.StartDoc(&di);    // Begin a new print job
            
            // Get the printing extents and store in the m\_rectDraw field of a 
            // CPrintInfo object
            CPrintInfo Info;
            Info.m\_rectDraw.SetRect(0,0, 
                                    dc.GetDeviceCaps(HORZRES), 
                                    dc.GetDeviceCaps(VERTRES));
            
            OnBeginPrinting(&dc, &Info);            // Call your "Init printing" function
            
            // Now, Print every Page!
            UINT page;
            for (page=Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK;page++){
            
                dc.StartPage();                     // begin new page
                Info.m\_nCurPage = page;
                PrintPage(&dc, &Info);                // Call your "Print page" function
                bPrintingOK = (dc.EndPage() > 0);   // end page
            }
            OnEndPrinting(&dc, &Info);              // Call your "Clean up" function
            
            if (bPrintingOK)
                dc.EndDoc();                        // end a print job
            else
                dc.AbortDoc();                      // abort job.
            
            dc.DeleteDC();                          // delete the printer DC	
            

            }

            // As from Chris Mauder.
            // Instead of Global I made it a member
            //
            // m_pView (Type COrderPageView) contains a list of PageFragments
            // Th

            B Offline
            B Offline
            Bram van Kampen
            wrote on last edited by
            #12

            Well I just Notice, I forgot to Select the Font into the Printer Device Context. That would of course have an impact! Can anyone spot other errors? :)

            Bram van Kampen

            1 Reply Last reply
            0
            • B Bram van Kampen

              Well, The Binary I get refuses to open. Here is my Printing Code:-

              ///////////////////////////////////////////////////////////////////////////////////
              //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
              //
              // PRINTING!!
              ///////////////////////////////////////////////////////////////////////////////////

              // OnClick the Print Button
              void CConfirmOrdersStep1Dlg::OnPrint()
              {
              if(CreateViewForPrinting()==false){
              AfxMessageBox("No Orders have been Marked for Printing");
              return;
              }
              CDC dc;
              CPrintDialog printDlg(FALSE);

              if (printDlg.DoModal() == IDCANCEL)     // Get printer settings from user
                  return;
              
              dc.Attach(printDlg.GetPrinterDC());     // Get and attach a printer DC
              dc.m\_bPrinting = TRUE;
              
              CString strTitle="Old Orders";                       // Get the application title
              //strTitle.LoadString(AFX\_IDS\_APP\_TITLE);
              

              // strTitle.Format("Date:Confirming Old Orders By:- %s-%s", UserName,Date);

              DOCINFO di;                             // Initialise print document details
              memset(&di, 0,sizeof (DOCINFO));
              di.cbSize = sizeof (DOCINFO);
              di.lpszDocName = strTitle;
              
              BOOL bPrintingOK = dc.StartDoc(&di);    // Begin a new print job
              
              // Get the printing extents and store in the m\_rectDraw field of a 
              // CPrintInfo object
              CPrintInfo Info;
              Info.m\_rectDraw.SetRect(0,0, 
                                      dc.GetDeviceCaps(HORZRES), 
                                      dc.GetDeviceCaps(VERTRES));
              
              OnBeginPrinting(&dc, &Info);            // Call your "Init printing" function
              
              // Now, Print every Page!
              UINT page;
              for (page=Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK;page++){
              
                  dc.StartPage();                     // begin new page
                  Info.m\_nCurPage = page;
                  PrintPage(&dc, &Info);                // Call your "Print page" function
                  bPrintingOK = (dc.EndPage() > 0);   // end page
              }
              OnEndPrinting(&dc, &Info);              // Call your "Clean up" function
              
              if (bPrintingOK)
                  dc.EndDoc();                        // end a print job
              else
                  dc.AbortDoc();                      // abort job.
              
              dc.DeleteDC();                          // delete the printer DC	
              

              }

              // As from Chris Mauder.
              // Instead of Global I made it a member
              //
              // m_pView (Type COrderPageView) contains a list of PageFragments
              // Th

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #13

              Bram van Kampen wrote:

              The Binary I get refuses to open.

              Not sure what that means, or what is missing. If you do not select the font into the DC then it will just use a default, so you should still see some output. Given that this is Chris's original code, you may want to try talking to him.

              B 1 Reply Last reply
              0
              • B Bram van Kampen

                Well, The Binary I get refuses to open. Here is my Printing Code:-

                ///////////////////////////////////////////////////////////////////////////////////
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                //
                // PRINTING!!
                ///////////////////////////////////////////////////////////////////////////////////

                // OnClick the Print Button
                void CConfirmOrdersStep1Dlg::OnPrint()
                {
                if(CreateViewForPrinting()==false){
                AfxMessageBox("No Orders have been Marked for Printing");
                return;
                }
                CDC dc;
                CPrintDialog printDlg(FALSE);

                if (printDlg.DoModal() == IDCANCEL)     // Get printer settings from user
                    return;
                
                dc.Attach(printDlg.GetPrinterDC());     // Get and attach a printer DC
                dc.m\_bPrinting = TRUE;
                
                CString strTitle="Old Orders";                       // Get the application title
                //strTitle.LoadString(AFX\_IDS\_APP\_TITLE);
                

                // strTitle.Format("Date:Confirming Old Orders By:- %s-%s", UserName,Date);

                DOCINFO di;                             // Initialise print document details
                memset(&di, 0,sizeof (DOCINFO));
                di.cbSize = sizeof (DOCINFO);
                di.lpszDocName = strTitle;
                
                BOOL bPrintingOK = dc.StartDoc(&di);    // Begin a new print job
                
                // Get the printing extents and store in the m\_rectDraw field of a 
                // CPrintInfo object
                CPrintInfo Info;
                Info.m\_rectDraw.SetRect(0,0, 
                                        dc.GetDeviceCaps(HORZRES), 
                                        dc.GetDeviceCaps(VERTRES));
                
                OnBeginPrinting(&dc, &Info);            // Call your "Init printing" function
                
                // Now, Print every Page!
                UINT page;
                for (page=Info.GetMinPage(); page <= Info.GetMaxPage() && bPrintingOK;page++){
                
                    dc.StartPage();                     // begin new page
                    Info.m\_nCurPage = page;
                    PrintPage(&dc, &Info);                // Call your "Print page" function
                    bPrintingOK = (dc.EndPage() > 0);   // end page
                }
                OnEndPrinting(&dc, &Info);              // Call your "Clean up" function
                
                if (bPrintingOK)
                    dc.EndDoc();                        // end a print job
                else
                    dc.AbortDoc();                      // abort job.
                
                dc.DeleteDC();                          // delete the printer DC	
                

                }

                // As from Chris Mauder.
                // Instead of Global I made it a member
                //
                // m_pView (Type COrderPageView) contains a list of PageFragments
                // Th

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #14

                I am not sure that you should be calling CView::OnBeginPrinting[^] in your code. That function will be called by the framework when printing is initiated.

                1 Reply Last reply
                0
                • L Lost User

                  Bram van Kampen wrote:

                  The Binary I get refuses to open.

                  Not sure what that means, or what is missing. If you do not select the font into the DC then it will just use a default, so you should still see some output. Given that this is Chris's original code, you may want to try talking to him.

                  B Offline
                  B Offline
                  Bram van Kampen
                  wrote on last edited by
                  #15

                  Wel, I get a Binary File not recognised by the XPS Reader. I can open it as Binary in a HexVieuwer, and get nothing recognisable.

                  Bram van Kampen

                  L 1 Reply Last reply
                  0
                  • B Bram van Kampen

                    Wel, I get a Binary File not recognised by the XPS Reader. I can open it as Binary in a HexVieuwer, and get nothing recognisable.

                    Bram van Kampen

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #16

                    When I look at an XPS print file it looks something like:

                    PK   µC'I  Metadata/Job_PT.xmlíW]s¢H}ߪý)Þ' &Ùh%NÝ4ZÁØ }Cè`|
                    ´¢óë÷¶ã̬‰™™§éòš{Îážþ¸póqGgK–6ÿþë&+žƒœ'bÈý9gKŠöÞ*3!²†ªþŒÅ^qs?O‹ôIœûi¬–< Ò²P«šVSµk5“H¾=Øbžr/fešÏ•íªà{Ú²,ÏËÚyš‡’£¢>š÷öõ'…🽠‚·QÊA²ÏÀ¤Ð°žÈ•ŠŸÿJdÎÖ˜FP¨{è*

                    which is fine, and the XPS reader opens it OK. As to why you cannot read yours is a total mystery. If you are using all the standard APIs (or their MFC equivalents) to create your print files, then they should at least be readable. Try changing the extension from .xps to .zip and have a look at the content then.

                    B 1 Reply Last reply
                    0
                    • L Lost User

                      When I look at an XPS print file it looks something like:

                      PK   µC'I  Metadata/Job_PT.xmlíW]s¢H}ߪý)Þ' &Ùh%NÝ4ZÁØ }Cè`|
                      ´¢óë÷¶ã̬‰™™§éòš{Îážþ¸póqGgK–6ÿþë&+žƒœ'bÈý9gKŠöÞ*3!²†ªþŒÅ^qs?O‹ôIœûi¬–< Ò²P«šVSµk5“H¾=Øbžr/fešÏ•íªà{Ú²,ÏËÚyš‡’£¢>š÷öõ'…🽠‚·QÊA²ÏÀ¤Ð°žÈ•ŠŸÿJdÎÖ˜FP¨{è*

                      which is fine, and the XPS reader opens it OK. As to why you cannot read yours is a total mystery. If you are using all the standard APIs (or their MFC equivalents) to create your print files, then they should at least be readable. Try changing the extension from .xps to .zip and have a look at the content then.

                      B Offline
                      B Offline
                      Bram van Kampen
                      wrote on last edited by
                      #17

                      Hi, Richard, Well, if it opens in your machine , there is evidently something wrong with my reader, and nothing wrong with the code I wrote to generate same. I'm away on a break for a few days. I had my 62nd Birthday 3 weeks ago, but, were unable to escape. We are trying enjoy life in semi retirement, with a small important money spinning business running in the background, powered by my software. I appreciate your comment, and will try changing the XPS ext to ZIP when I'm back. I Think that you know that I write software for Laundrettes and Dry-Cleaners, specifically for our own chain. There are No Trade or Other secrets buried in the Text Example I Sent. It is a Fictitious Customer with a Fictitious ancient Order. (The Bane of a laundrette is people not coming back to pay and collect, It Clogs up the shop, the work is done, but, the Till does not ring. ) The Program I am writing now, is a concerted attempt to attack this, by contacting customers. The First step there is, to ensure that ancient Orders that appear on the database, are still present in the shop. Whereas we Trust our staff, an order could have been given out, without the order being rang in, the staff pocketing the sale, and the Item remaining on the Database. At any rate, we do not want to contact customers over long forgotten items, when we no longer poses them, for whatever reason. It also gives staff an other activity at quiet Times. Instead of drinking cups of tea, they have a Screen of alternative, and More Productive activity. Making Phone Calls, and finding People's goods. If people's goods can not be found, then there is no point in ringing the customer. Let sleeping dogs lie, and Management writes the item off. We tried it manually, and got things like "Oh I forgot about that, I will collect it next Saturday" Saturday came and went, we all forgot, order still here. This new program will pursue only say 10 old orders at the time, but these orders will be pursued vigorously. Items Promised to be Collected By a date, will disappear of the ToDo List, but, will re-appear there after that date, if at that stage not collected and paid. The Interface is being designed so that Junior Staff can handle it, kicking major decisions back upstairs. The Document I tried to print was a form, for staff to go around the shop, and find the goods. The First Step. When you Opened the XPS File, could you read the Text as Follows:-

                       Finding Old Orders in the Shop     
                      

                      Printed by on 01 09 16 -

                      L 1 Reply Last reply
                      0
                      • B Bram van Kampen

                        Hi, Richard, Well, if it opens in your machine , there is evidently something wrong with my reader, and nothing wrong with the code I wrote to generate same. I'm away on a break for a few days. I had my 62nd Birthday 3 weeks ago, but, were unable to escape. We are trying enjoy life in semi retirement, with a small important money spinning business running in the background, powered by my software. I appreciate your comment, and will try changing the XPS ext to ZIP when I'm back. I Think that you know that I write software for Laundrettes and Dry-Cleaners, specifically for our own chain. There are No Trade or Other secrets buried in the Text Example I Sent. It is a Fictitious Customer with a Fictitious ancient Order. (The Bane of a laundrette is people not coming back to pay and collect, It Clogs up the shop, the work is done, but, the Till does not ring. ) The Program I am writing now, is a concerted attempt to attack this, by contacting customers. The First step there is, to ensure that ancient Orders that appear on the database, are still present in the shop. Whereas we Trust our staff, an order could have been given out, without the order being rang in, the staff pocketing the sale, and the Item remaining on the Database. At any rate, we do not want to contact customers over long forgotten items, when we no longer poses them, for whatever reason. It also gives staff an other activity at quiet Times. Instead of drinking cups of tea, they have a Screen of alternative, and More Productive activity. Making Phone Calls, and finding People's goods. If people's goods can not be found, then there is no point in ringing the customer. Let sleeping dogs lie, and Management writes the item off. We tried it manually, and got things like "Oh I forgot about that, I will collect it next Saturday" Saturday came and went, we all forgot, order still here. This new program will pursue only say 10 old orders at the time, but these orders will be pursued vigorously. Items Promised to be Collected By a date, will disappear of the ToDo List, but, will re-appear there after that date, if at that stage not collected and paid. The Interface is being designed so that Junior Staff can handle it, kicking major decisions back upstairs. The Document I tried to print was a form, for staff to go around the shop, and find the goods. The First Step. When you Opened the XPS File, could you read the Text as Follows:-

                         Finding Old Orders in the Shop     
                        

                        Printed by on 01 09 16 -

                        L Offline
                        L Offline
                        Lost User
                        wrote on last edited by
                        #18

                        Hi Bram, well I'm a few years older than you, so in theory I should have more knowledge locked in my brain. But you know what they say about theory and practice. When I said I could open the XPS file, I meant one that I generated here. If you can send me the one you generate I could have a look at it for you. Send me a private email and I can give you an address, or put it up on one of the public staging sites.

                        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