Solved

How to print postscript file in dialog based application?

Posted on 2004-04-08
9
474 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 97
viewing source code from eclipse 13 88
sumHeights  challenge 17 66
"Black Box" Testing of Control System Software 2 26
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now