piping a text file to printer

delphi question:

I want to write a program that does the following:
1. ftp text file from HP UNIX to pc:      i know how to do this
2. send the text file to the printer (printer is on a LAN)

How do you do step 2?   Do i have to read to text file first
or is there a command to just send it over to the printer?

Who is Participating?
edeyConnect With a Mentor Commented:
Just include the printers .dcu & set the printer objects (you don't have to declare it yourself) orientation property:

Orientation determines if the print job prints vertically or horizontally on a page.

TPrinterOrientation = (poPortrait, poLandscape);
property Orientation: TPrinterOrientation;


Use Orientation to determine if a print job prints in landscape or portrait.
TPrinterOrientation is the type of the Orienation property. These are the possible values for TPrinterOrientation:

Table Part 0.1            

Value      Meaning
poPortrait      The print job prints vertically on the page.
poLandscape      The print job prints horizontally on the page.

I would assume that the text file would have to be rendered first.  Perhaps the easiest method of doing so would be to create a TRichEdit, use it to load the files, then call it's print method.  You may have to select a printer, coding wise it would be easiest to do so using a printer dialog & some user input (manually select the printer), else, if you know the name of the printer you can use the TPrinter object to select it as the current active printer.  If you want to code the whole thing with out using a form, you would have to  write out each line of text on the TPrinter's canvas (useing a TStrings descendant to load the file).  Else, if you have an application to handle the file's .ext, you can use shell execute with 'print' parameter:

The ShellExecute function opens or prints a specified file. The file can be an executable file or a document file. See ShellExecuteEx also.

HINSTANCE ShellExecute(

    HWND  hwnd,      // handle to parent window
    LPCTSTR  lpOperation,      // pointer to string that specifies operation to perform
    LPCTSTR  lpFile,      // pointer to filename string
    LPTSTR  lpParameters,      // pointer to string that specifies executable-file parameters
    LPCTSTR  lpDirectory,      // pointer to string that specifies default directory
    INT  nShowCmd       // whether file is shown when opened

Pointer to a null-terminated string that specifies the operation to perform. The following operation strings are valid:

String      Meaning
"open"      The function opens the file specified by lpFile. The file can be an executable file or a document file.
"print"      The function prints the file specified by lpFile. The file should be a document file. If the file is an executable file, the function opens the file, as if "open" had been specified.

waipahuAuthor Commented:
 rc := ShellExecute(Handle, 'print', 'test.rpt', '', 'd:\rsgftp', SW_SHOWNORMAL);

I wanted to print a text file called "test.rpt" and it is
in the directory "d:\rsgftp".  But i get a return code of 2.
What is the problem????

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.

waipahuAuthor Commented:
I got it to work!!!!! thanks
However, is there anyway to change the FONT?
I need to change the font to courier, pitch 8cpi
and also landscape.    HP Laserjet 4si.

waipahuAuthor Commented:
Also, I notice that if my file ends with .txt it will work.
But if my extenstion is other than .txt it will not work.
Also, it is using notepad to print my file.
Is there a way to use wordpad instead?
To make it work with other .ext's you would need to register those .ext's as being wordpad documents, though when considering the font problem it may be easier to use a TRichEdit. Something like this:

with TRichEdit.create(self) do
 wordWrap := false;
//or set the richedit dim's yourself
 selStart := 0;
 selLength := length(text);

note: if the doc doesn't print to the hp, include the printers .dcu, & check the printer objects printers property (it's a TStrings) then set the printer's printerIndex to the matching printer description.

waipahuAuthor Commented:
the RICHEDT works fine!

I was able to change the font and it works.
How do you change it to print to landscape?????

All Courses

From novice to tech pro — start learning today.