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?

Thanks
waipahuAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

edeyCommented:
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
   );
lpOperation

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.



GL
mike
0
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????

0
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.

Thanks!
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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?
0
edeyCommented:
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
begin
 wordWrap := false;
//or set the richedit dim's yourself
 lines.loadFromFile(fileName);
 selStart := 0;
 selLength := length(text);
 print(fileName);
 free;
end;


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.

GL
Mike
0
waipahuAuthor Commented:
THANK YOU!
the RICHEDT works fine!

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

Thanks
0
edeyCommented:
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;

Description

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.



GL
Mike
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.