[DUG] Printing text line by line
John Bird
johnkbird at paradise.net.nz
Wed Aug 10 23:42:26 NZST 2005
With a generic text printer it should be simple.
I don't know if the form-feed is in the printer driver or the interface of
Delphi with the printer...I think its probably in the Delphi part, because
the approach below does not produce a form-feed.
With non-Delphi software I have done printing to cheque and receipt printers
simply, there are several ways. I think from memory although the logical
thing is to open the printer device, eg LPT1 and do like a WRITELN of the
lines to it and then close it (I tried this in the other language) there
were reasons to not do this which I don't recall - probably errors with
device access in XP etc.
What I ended up doing was writing the receipt text to a temporary file, and
generating a small batch file which would effectively be called say
PEDROLP.BAT and would contain
NET USE LPT5 %1 /YES
COPY %2 LPT5
NET USE LPT5 /DELETE/YES
The command to print the file would be from Shellexec with the batch file
name and parameters effectively generating a commmand like
PEDROLP \\SERVER\PRINTER1 TempFilename
For example:
param:='\\SERVER\PRINTER '+TempFileName;
if ShellExecute(Application.Mainform.Handle, 'open',Pchar('PEDROLP.BAT'),
nil, PChar(param), SW_SHOWNORMAL) <= 32 then
ShowMessage(SysErrorMessage(GetLastError));
This allows you to address the printer with its network name. If printing
on a non-network, you need to use a variant of this approach which instead
copies the temp file to LPT1 etc.....in practice I did it all with one more
complex batch file....contact me for more details.
This was the tidiest approach for software where it was preferrable to print
using a shell command line, also used to use PRFILE32.EXE - a freeware
utility that allows full command line printing to windows printers.
Combinations of all these allowed pure DOS software to print to any Windows
print queues, Network printers, IP printers and USB printers with control
over formatting and form-feeds.
John B
_______________________________________________
Delphi mailing list
Delphi at ns3.123.co.nz http://ns3.123.co.nz/mailman/listinfo/delphi
More information about the Delphi
mailing list