Advice needed about printing Label Printers

Advice needed about printing Label Printers

Postby Horizon » Thu Jun 25, 2009 10:06 am

Hi,

I used to print my labels to my local printer from programs like below.

First I create a new file from my template file and then print like that

Code: Select all  Expand view

WinExec("cmd /c YAZ.BAT")


YAZ.BAT
Code: Select all  Expand view
TYPE NewFile.PRN > PRN


I need to write my NewFile.PRN without using winexec and Batch file to label printers defined in Control Panel of Windows.

How Can I do it?

Thanks in advance.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm

Re: Advice needed about printing Label Printers

Postby hua » Fri Jun 26, 2009 2:20 am

xHarbour has a function PrintFileRaw(). Maybe that could help you

PrintFileRaw()
Prints a file to a Windows printer in RAW mode.

Syntax
PrintFileRaw( <cPrinterName>, ;
<cFileName> , ;
[<cJobTitle>] ) --> nErrorCode


Arguments
<cPrinter>
This is a character string holding the name of the printer to use for printing.

<cFileName>
The file to print must be specified as a character string, including path and extension. If the path is omitted, the file is searched in the current directory.

<cJobTitle>
This is an optional character string which appears as print job description in the spooler. It defaults to <cFileName>. Return
The function returns 1 on success or a value less than zero on error. See the example for error codes.

Description
Function PrintFileRaw() prints a file to a Windows printer in RAW mode. This restricts file types for printing to enhanced metafiles (EMF), ASCII text, and raw data, which includes all printer specific file types such as PostScript and PCL. The file is sent to the Windows spooler which processes the print job. The function returns zero when the file is successfully transferred to the spooler. Note that this is no guarantee for a printout. If the physical printer is out of paper, for example, the spooler reports an error to the user. This type of failure cannot be detected by PrintFileRaw().


Example
Code: Select all  Expand view
// The example prints a file in RAW mode and demonstrates
// the possible return values of PrintFileRaw().

   PROCEDURE Main()
      LOCAL cPrinter := GetDefaultPrinter()
      LOCAL cFile    := "MyFile.Txt"
      LOCAL nResult  := -1
      LOCAL cMsg     := "PrintFileRaw(): "

      CLS
      IF Empty( cPrinter )
         ? "No default printer found"
         QUIT
      ENDIF

      nResult := PrintFileRaw( cPrinter, cFile, "Test for PrintFileRaw()" )

      SWITCH nResult
      CASE -1
         cMsg += "Invalid parameters passed to function" ; EXIT
      CASE -2
         cMsg += "WinAPI OpenPrinter() call failed"      ; EXIT
      CASE -3
         cMsg += "WinAPI StartDocPrinter() call failed"  ; EXIT
      CASE -4
         cMsg += "WinAPI StartPagePrinter() call failed" ; EXIT
      CASE -5
         cMsg += "WinAPI malloc() of memory failed"      ; EXIT
      CASE -6
         cMsg += "File " + cFile + " not found"          ; EXIT
      DEFAULT
         cMsg += cFile + " PRINTED OK!!!"
      END

      ? cMsg
   RETURN
 
FWH 11.08/FWH 19.12
BCC5.82/BCC7.3
xHarbour/Harbour
hua
 
Posts: 1072
Joined: Fri Oct 28, 2005 2:27 am

Re: Advice needed about printing Label Printers

Postby Horizon » Fri Jun 26, 2009 9:18 pm

Thank you very much hua.

It works.
Regards,

Hakan ONEMLI

Harbour & MSVC 2022 & FWH 23.04
Horizon
 
Posts: 1322
Joined: Fri May 23, 2008 1:33 pm


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot], wartiaga and 92 guests