Identifying which printer to receive and print a text file
Hello,
Goal:
Identifying which printer to receive and print a text file.
My users along with myself are on a network and may also have a local dot
matrix printer attached. I would like to select the printer without having
a person go into control panel to set their default printer to be the
recipient of the newly created text file.
The text file was created by setting the Report.DeviceFile :=
'ReportTextFile';
Report.TextFileName := 'text.txt';
Report.AllowPrintToFile := True;
I am looking at the examples in the rbuilder\demo project (in the area of
101-110 Print to File). The current examples do not show how to set which
printer to print the text file.
Your assistance will be greatly appreciated.
Karen
Your assistance
Goal:
Identifying which printer to receive and print a text file.
My users along with myself are on a network and may also have a local dot
matrix printer attached. I would like to select the printer without having
a person go into control panel to set their default printer to be the
recipient of the newly created text file.
The text file was created by setting the Report.DeviceFile :=
'ReportTextFile';
Report.TextFileName := 'text.txt';
Report.AllowPrintToFile := True;
I am looking at the examples in the rbuilder\demo project (in the area of
101-110 Print to File). The current examples do not show how to set which
printer to print the text file.
Your assistance will be greatly appreciated.
Karen
Your assistance
This discussion has been closed.
Comments
By design, Printing to a text file, simply creates a .txt file.
If you want to print to the printer....
a. Print directly to the printer (do not create a text file)
OR
b. Print to the .txt file and then write code to send the .txt to the
printer (see tech tip below)
-----------------------------------------------
Tech Tip: Send TextFile to Printer
-----------------------------------------------
I designed a application that exports the report to a .txt
file using ReportTextFile device.
How can I Send the text file to the printer?
The following procedure will send the .txt file to
the printer using Delphi's TPrinter object.
uses
Printers;
procedure SendTextFileToPrinter(aFileName: String);
var
lsLines: TStringList;
lOutputFile: TextFile;
liIndex: Integer;
begin
lsLines := TStringList.Create;
try
lsLines.LoadFromFile(aFileName);
AssignPrn(lOutputFile);
Rewrite(lOutputFile);
for liIndex := 0 to lsLines.Count-1 do
Writeln(lOutputFile, lsLines[liIndex]);
CloseFile(lOutputFile);
finally
lsLines.Free;
end;
end;
--
Tech Support mailto:support@digital-metaphors.com
Digital Metaphors http://www.digital-metaphors.com
--
Nard Moseley
Digital Metaphors Corporation
http://www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Thanks for responding. Yes I did use the tech tip example of
SendTextFileToPrinter(aFileName : string) in creating the text file and
sending the file.
As I mentioned,
How do I get the file to a "specific" printer that is not currently their
windows default printer.
Your assistance is greatly appreciated.
Thanks,
Karen
Sending a text file to the printer uses a global instance of the Delphi
TPrinter class. You can use the Delphi Printer function to access the global
printer object. The TPrinter.Printers property contains the list of
installed printers. The TPrinter.PrinterIndex properties indicates which
printer in the list is selected. (All of this information is in the Delphi
online help file. Note: ReportBuilder uses its own TppPrinter class rather
than TPrinter class. But for sending a text file to the printer, you need to
use the TPrinter class).
Example:
uses
Printers;
begin
Printer.PrinterIndex := -1; // select the default printer
Printer.PrinterIndex := 0; // select the first printer in the
Printer.Printers[] list.
end;
--
Nard Moseley
Digital Metaphors Corporation
http://www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Just wanted to let you know that I have read the Tech Tip: Controlling the
Printer and the examples listed used:
the report object inspector
the file | Page Setup dialog
report.printersetup object.
Since this is a text file created by running the report builder, these
examples did not provide the assistance I needed to select and send the text
file to a "specific" dot matrix printer that is "not" set as a default
printer.
Your assistance is greatly appreciated.
Thanks,
Karen
Have a great day!