FT_PCHR

FT_PCHR()
 Convert printer control codes

 Syntax

       FT_PCHR( <cString> )  ->  <cPrinterFormat>

 Arguments

       <cString> is the representation of the printer control codes in
       text, numeric, hexadecimal, Epson command format, or any combination
       separated by commas.

 Returns

       A character string of printer control codes.

 Description

       This function is useful for allowing the user to enter printer
       control codes in text (enclosed in double quotes), numeric,
       hexadecimal, or Epson commands preceded by a slash and returns
       the printer control code equivalent.

       NOTES"

         - Combinations of text, numbers, hex, and commands must be
            separated by commas ("A",27,&1B,/RESET).
         - Text must be enclosed in double quotes ("x").
         - Hexadecimal must be preceded by an ampersand (&1B).
         - Epson commands, listed below, must be preceded by a forward
            slash (/RESET).

         Epson commands: (slash commands are specific to the Epson)

           Job Control:

           /RESET or /INIT   Reset or initialize the printer
           /BELL  or /BEEP   Cause the printer's speaker to beep (not HS)
           /CAN              Clear print buffers (not MX)
           /SLOW             Set low speed mode (not CR, HS, MX)
           /FAST             Cancel low speed mode (not CR, HS, MX)
           /ONE              Select Unidirectional mode
           /TWO              Select Directional mode
           /ON               Activate printer
           /OFF              Turn off printer

           /FF or /EJECT     Form Feed

           Page Control:

           /1/6              Set 6 lines per inch
           /1/8              Set 8 lines per inch
           /SKIP             Set Skip perforation ON
           /SKIPOFF          Set Skip perforation OFF

           Font Selection and Manipulation:

           /ITALIC           Select italic char. set  (only FX86, EX, LX,
                                                           no LQ-1500, SX)
           /GRAPHIC          Select graphic char. set (only FX86, EX, LX,
                                                           no LQ-1500, SX)
           /ROMAN            Choose Roman font
           /SANS             Choose Sans Serif font
           /DRAFT            Choose draft
           /NLQ              Choose near letter quality
           /PICA             Choose 10 chars per inch
           /ELITE            Choose 12 chars per inch
           /COND or /SI      Choose 15 chars per inch
           /EMPH             Turn emphasize on
           /EMPHOFF          Turn emphasize off
           /SPANISH          Select spanish international char set
           /USA              Select USA international char set

 Examples

       cSetUp := '27,116,1'
       Set Print ON
       ? FT_PCHR( cSetUp )      ->  (CHR(27)+CHR(116)+CHR(1))
                                            <select Epson char. graphics>

       ? FT_PCHR( '27,"x",0' )  ->  (CHR(27)+CHR(120)+CHR(0))
                                         <Epson draft mode>

       ? FT_PCHR( '&1B,"E"'  )  ->  (CHR(27)+CHR(69))   <HP reset>

       ? FT_PCHR( '/ELITE,/NLQ' ) ->(CHR(27)+CHR(77)+CHR(27)+CHR(120)+CHR(1))
                                <Epson elite & near letter quality>

 Source: PCHR.PRG

 Author: Jim Gale

 

FT_ESCCODE

FT_ESCCODE()
 Convert Lotus style escape codes

 Syntax

      FT_ESCCODE( <cASCII> )  -> <cPrinterFormat>

 Arguments

     <cASCII> is the ASCII representation of the printer control
                codes in Lotus 123 format (e.g. "27E" for Chr(27)+"E")

                "\nnn" will be converted to Chr(nnn)
                "\\" will be converted to "\"

 Returns

     The binary version of an ASCII coded printer setup string.

 Description

     This function is useful for allowing the user to enter printer
     control codes in Lotus-style ASCII format, and then having
     this function convert that code to the format that the printer
     needs to receive.

 Examples

     cSetup = "15"          // default = Epson compressed print
     UserInput( @cSetup )     // Let user modify setup code
     SET DEVICE TO PRINT      // get ready to print
     ?? FT_ESCCODE( cSetup )  // Output the converted code

 Source: PRTESC.PRG

 Author: Steven Tyrakowski

 

Print File

 Send a file to printer

Once builded a file contains lines to print, seems it’s easy sending that file to printer :

COPY FILE command send entire file to another file or a device :

COPY FILE <xcSourceFile> TO <xcTargetFile>|<xcDevice>

Arguments:

<xcSourceFile> is the name of the source file to COPY including the extension.

<xcTargetFile> is the name of the target file including the extension.

<xcDevice> is the name of the device where all subsequent output will be sent. You can specify a device name as a literal character string or a character expression enclosed in parentheses. Additionally, a device can be either local or network. If you COPY TO a non-existing device you create a file with the name of the device. When specifying device names, do not use a trailing colon.

Example :

COPY FILE Prnfile.txt TO LPT1

Remember that above last command doesn’t work under Windows. Almost all Clipper commands and functions are usable in Harbour. You can apply above tests with Harbour too. And the result not changed again. Because problem isn’t compiler, but hardware and OS difference. Harbour offers additional (extended) easy ways to manage printer(s) :

 WIN_PRINTEREXISTS()     (old name: PRINTEREXISTS())
 WIN_PRINTERSTATUS()     (old name: XISPRINTER())
 WIN_PRINTERPORTTONAME() (old name: PRINTERPORTTONAME())
 WIN_PRINTERLIST()       (old name: GETPRINTERS())
 WIN_PRINTERGETDEFAULT() (old name: GETDEFAULTPRINTER())
 WIN_PRINTERSETDEFAULT() (old name: SETDEFAULTPRINTER())
 WIN_PRINTFILERAW()      (old name: PRINTFILERAW())
For sending a file to printer we need only two of above function :
 WIN_PRINTERGETDEFAULT() 
 WIN_PRINTFILERAW()

If we have alredy above Prnfile.txt, sending it to printer seems easy :

 cDefaultPrinter := WIN_PRINTERGETDEFAULT() 
 WIN_PRINTFILERAW( cDefaultPrinter, Prnfile.txt )

Is that all ?

WIN_PRINTFILERAW() returns 1 if sending to printer was successful. If you test this, probably you will get 1.

May be easy like this ?

Unfortunatelly answer is “sometime” …

Although WIN_PRINTFILERAW() said “sending is successful” you may get nothing from printer.

What is meaning of “sometime” ? May be “sometime” in physic ?

In physic no, but in Windows yes !

What ?

Because some printers or some versions of Windows due to something obscure …

… doesn’t support “raw” printing 😦

And a more interesting thing :

You may send your “raw” file to printer via NotePad program of Windows :

cOutFName := "Test_Raw.txt"
cCmd := "NOTEPAD /P " + cOutFName

RUN ( cCmd)

( The “/P” parameter / switch means direct printing;  without NotePad open)

When sent this file by WIN_PRINTFILERAW() to printer noting happen, but by above (notepad) way sending is successful 😦

It seems that NOTEPAD build a “printable” document from our “raw” file and send this document to printer instead of our file.

However, NOTEPAD always add print file name to top, and page number to bottom of document; and treats our “printer control codes” as data, so printers never use them in “right”  way.

Other ways :

EXECUTE FILE "NOTEPAD.EXE" PARAMETERS cFileName

(  EXECUTE FILE   is a HMG command.

SHELLEXECUTE( 0, "print", cFileName )