Print on a specific printer
Leo Bidi
Montevideo, Uruguay
Hi, I need to print a report on a specific printer that is not selected by any dialog, just directly.
The thing is that its a shared printer and used by a few stations.
My question is how I define in my report the name of the printer.
Do I have to assing the "real" name of the printer or the "shared" name?
Or both must be the same?
And how I define in my report that is THAT printer?.
I have this command but does not function like I'd like.
AIndex := frxPrinters.IndexOf('HP PSC 750'); <-- it's this correct?? what name?
if AIndex <> 0 then
begin
frxPrinters.PrinterIndex := AIndex;
Rep_Estudio.PrintOptions.Printer := frxPrinters[AIndex].Name;
end;
Thanks so much.
Leo
The thing is that its a shared printer and used by a few stations.
My question is how I define in my report the name of the printer.
Do I have to assing the "real" name of the printer or the "shared" name?
Or both must be the same?
And how I define in my report that is THAT printer?.
I have this command but does not function like I'd like.
AIndex := frxPrinters.IndexOf('HP PSC 750'); <-- it's this correct?? what name?
if AIndex <> 0 then
begin
frxPrinters.PrinterIndex := AIndex;
Rep_Estudio.PrintOptions.Printer := frxPrinters[AIndex].Name;
end;
Thanks so much.
Leo
Comments
Your code will fail one day.
You must use the name of the printer as it appears on the work station. As any printer can be renamed, one can never be certain of its name. On work station 1 the printer may indeed be 'HP PSC 750' but on work station 2 it may be 'Invoice' and on WS3 it may be 'Documents', all referring to the same physical printer.
This means that somewhere in your application you must have a setting which identifies the right printer on this work station. The only exception is of course if this is the default printer.
(TComboBox).Items := Printer.Printers;
(TComboBox).Itemindex := 0;
// select printer from list, somewhere in your app and store in a suitable place
printerName := GetItSomeHowFunction; //
// someone may have renamed or deleted it
if Printer.Printers.IndexOf( printerName ) < 0 then
printerName := defaultPrinterName; // or throw exception
Rep_Estudio.PrintOptions.Printer := printerName;
Note that if you load the report at run-time from file or via stream all settings will be set to what they were at design time. Above code must be executed after loading the report.