Solved

How to print postscript file in dialog based application?

Posted on 2004-04-08
9
475 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
crystal report check box and wingdings font 7 187
notReplace  challenge 53 125
building a service to accessed via telnet client, want colors ? 4 88
Change to event 1 111
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 …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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…

776 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