Print on a specific printer

Leo BidiLeo Bidi Montevideo, Uruguay
edited 1:44AM in FastReport 4.0
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

Comments

  • edited 1:44AM
    Leo Bidi wrote: »
    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;

    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.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.