Solved

How to print postscript file in dialog based application?

Posted on 2004-04-08
9
478 Views
Last Modified: 2013-12-03
I have a postscript file need to be printed in a dialog application, I want to have print button
in the dialog window, when "Print" button  is clicked,
print dialog starts, so user can choose the printer, font,
pages.... , then it prints the postscript file stored at my local directory. I don't need to view this file.

Thanks.
Hanqian
 
0
Comment
Question by:Hanqian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 6

Expert Comment

by:joghurt
ID: 10784026
What is your exact problem? What are the steps where you're stuck?
Or do you want us to do all the programming work instead of you?
0
 

Author Comment

by:Hanqian
ID: 10784188
I know how to start print diaplog, but I don't know how to let
printer know what file to print?
0
 

Author Comment

by:Hanqian
ID: 10784922
I have the following code, but I couldn't make it work.

      // Print the doc.
      CPrintDialog dlgPrint (FALSE, PD_ALLPAGES, this);

      if (dlgPrint.DoModal() == IDOK) {
      CDC dcPrint;
                  dcPrint.Attach (dlgPrint.GetPrinterDC ());

                  // Create and fill a DOCINFO structure
                  DOCINFO myPrintJob;
                  myPrintJob.cbSize = sizeof(m_sigImageLen);
                  myPrintJob.lpszDocName = tmpDocFile;
                  myPrintJob.lpszOutput = NULL;
                  myPrintJob.lpszDatatype = NULL;
                  myPrintJob.fwType = NULL;

                  // Start to print file.
                  if (dcPrint.StartDoc(&myPrintJob) >= 0) {
                        dcPrint.StartPage();
                  //      dcPrint.TextOut(0,0,"My Samll Print Job");
                        dcPrint.EndPage();
                        dcPrint.EndDoc();
                  }
                  dcPrint.DeleteDC();
            }
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Hanqian
ID: 10784954
I have the following code, but I couldn't make it work from here.
How to link postscript file to printer?

      // Print the doc.
      CPrintDialog dlgPrint (FALSE, PD_ALLPAGES, this);

      if (dlgPrint.DoModal() == IDOK) {
      CDC dcPrint;
      dcPrint.Attach (dlgPrint.GetPrinterDC ());

      // Create and fill a DOCINFO structure
      DOCINFO myPrintJob;
      myPrintJob.cbSize = sizeof(?);
      myPrintJob.lpszDocName = FileName;
      myPrintJob.lpszOutput = NULL;
      myPrintJob.lpszDatatype = NULL;
      myPrintJob.fwType = NULL;

      // Start to print file.
      if (dcPrint.StartDoc(&myPrintJob) >= 0) {
              // Don't know waht to add here??
      dcPrint.EndDoc();
      }
      dcPrint.DeleteDC();
}
0
 
LVL 6

Accepted Solution

by:
joghurt earned 300 total points
ID: 10785638
myPrintJob.lpszDocName is simply the document/job name you'll see when you open the printer properties and check that jobs waiting for printing.

Assuming your postscript file is understood by your printer, you only have to send it to the printer as raw data.
You won't need to create a DC, neither will you have to use StartDoc.

bool SendFileToPrinter (const char* fnm)
{
      char                        buffer[8192];
      HANDLE                        hFile, hPrinter;
      DWORD                        numRead, numWritten;
      bool                        success;
      DOC_INFO_1                  docInfo;
      char                        dataType[16] = "RAW";     // MUST be uppercase, otherwise won't work on Win9x.
      char*                        p;


      hFile = CreateFile (fnm, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
      if (hFile == INVALID_HANDLE_VALUE)
            return (false);

      if (!OpenPrinter (defPrnName, &hPrinter, NULL)) {
            CloseHandle (hFile);
            return (false);
      }

      ZeroMemory (&docInfo, sizeof (docInfo));
      docInfo.pDocName = fnm;
      docInfo.pDatatype = dataType;
      success = (StartDocPrinter (hPrinter, 1, (LPBYTE) &docInfo) != 0);

      for ( ; success; ) {
            success = ReadFile (hFile, buffer, sizeof (buffer), &numRead, NULL);
            if (!success || numRead == 0)
                  break;
            success = WritePrinter (hPrinter, buffer, numRead, &numWritten);
            if (numRead != numWritten)
                  success = false;
      }

      EndDocPrinter (hPrinter);
      ClosePrinter (hPrinter);
      CloseHandle (hFile);

      return (success);
}
0
 

Author Comment

by:Hanqian
ID: 10785790
Do I need to add some header file?, it complains function:
OpenPrinter(),
StartDocPrinter(),
WritePrinter(),
EndDocPrinter(),
ClosePrinter(),
are undeclared identifiers.

Thanks.
Hanqian

0
 
LVL 6

Expert Comment

by:joghurt
ID: 10785961
<windows.h>
But I don't understand. If DOCINFO is defnied, these functions also should be defined.
0
 

Author Comment

by:Hanqian
ID: 10786339
Right now I hard code the name of printer, it works well.
Thanks a lot.  

BTW  if it doesn't take your much time,
do you know how to get name of the default printer for this function
OpenPrinter (defPrnName, &hPrinter, NULL)) ?

Thanks.
Hanqian
0
 
LVL 6

Expert Comment

by:joghurt
ID: 10786719
Ask another question (for only a few points if you don't have much) and I'll tell you.
(Just that if someone searches through question titles, should find the solution for that question.)
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
List out all word 7 351
sameEnds challenge 3 194
Doc'in system (example?) BA 7 126
mapAB Challlenge 35 180
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question