Solved

How to print postscript file in dialog based application?

Posted on 2004-04-08
9
476 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Detect CR LF to each line 12 170
Set Font and Size on Excel Template 2 118
conditional code and condition difference 9 84
withoutTen challenge 14 131
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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…

856 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