Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to print postscript file in dialog based application?

Posted on 2004-04-08
9
Medium Priority
?
480 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 

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 1200 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
In this post we will learn different types of Android Layout and some basics of an Android App.
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

670 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