How to specify a "not default" printer?
Whatever printername i specify, it always prints to the default printer
{*** Set Report Values ***}
rsClientReport.PrinterSetup.PrinterName := DocumentPrinterName;
rsClientReport.VolumeName := 'DefaultVolume';
rsClientReport.ReportName := DocumentName;
rsClientReport.PrinterSetup.Copies := DocumentCopies;
{*** Clear Local and Remote Cache ***}
rsClientReport.DeviceType := 'Printer';
rsClientReport.RefreshRequest := True;
rsClientReport.AutoSearchGroups.Clear;
rsClientReport.Reset;
{*** Print The Report *** }
rsClientReport.Print;
As a result the Autosearchfields are requested:
procedure TFrmDocument.rsClientReportReceiveAutoSearchFields(Sender:
TObject);
begin
with (Sender as TrsClientReport) do begin
ShowAutoSearchDialog := false;
if (AutoSearchFields[0].FieldName = 'CHEQUECODE') then begin
AutoSearchFields[0].SearchExpression := IntToStr(ChequeCode);
end;
PrintToDevices;
end;
end;
What's wrong with my approach?
Olivier Peter.
{*** Set Report Values ***}
rsClientReport.PrinterSetup.PrinterName := DocumentPrinterName;
rsClientReport.VolumeName := 'DefaultVolume';
rsClientReport.ReportName := DocumentName;
rsClientReport.PrinterSetup.Copies := DocumentCopies;
{*** Clear Local and Remote Cache ***}
rsClientReport.DeviceType := 'Printer';
rsClientReport.RefreshRequest := True;
rsClientReport.AutoSearchGroups.Clear;
rsClientReport.Reset;
{*** Print The Report *** }
rsClientReport.Print;
As a result the Autosearchfields are requested:
procedure TFrmDocument.rsClientReportReceiveAutoSearchFields(Sender:
TObject);
begin
with (Sender as TrsClientReport) do begin
ShowAutoSearchDialog := false;
if (AutoSearchFields[0].FieldName = 'CHEQUECODE') then begin
AutoSearchFields[0].SearchExpression := IntToStr(ChequeCode);
end;
PrintToDevices;
end;
end;
What's wrong with my approach?
Olivier Peter.
This discussion has been closed.
Comments
because of your call to Report.Print, then the printer setup is transferred
from the dialog to the page objects that are created as the report is
generated, and the printer setup on the report is not assigned to the
selected printer, unless Report.SavePrinterSetup is true. Then, when you
call PrintToDevices in your subsequent event handler for
ReceiveAutoSearchFields, it will use the printer setup that you had on your
report object originally and not what you specified in the print dialog. Try
setting Report.SavePrinterSetup to true if you want to try this. However, I
don't think you should call PrintToDevices in an event handler because you
are executing inside a call to Print already. If you want to print to a
device, then cache the pages and make that call after you call Print, that
way you can just send the cahced pages to another device without having to
rerequest the autosearch values.
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
I've added the 'rsClientReport.SavePrinterSetup := True;'
and removed the 'PrintToDevices';
procedure TFrmDocumentPrint.FormShow(Sender: TObject);
begin
DocumentPrinters := TPrinter.Create;
CmbPrinters.Items := DocumentPrinters.Printers; //Assign Printernames
to combobox
DocumentPRinters.Free;
end;
procedure TFrmDocumentPrint.BtnPrintClick(Sender: TObject);
begin
rsClientReport.DeviceType := 'Printer';
rsClientReport.PrinterSetup.PrinterName :=
CmbPrinters.Items[CmbPrinters.ItemIndex]; //Selected Printer in combobox
rsClientReport.VolumeName := 'Examples';
rsClientReport.ReportName := 'Invoice';
rsClientReport.PrinterSetup.Copies := 1;
rsClientReport.SavePrinterSetup := True;
end;
procedure TFrmDocument.rsClientReportReceiveAutoSearchFields(Sender:
TObject);
begin
with (Sender as TrsClientReport) do begin
ShowAutoSearchDialog := false;
if (AutoSearchFields[0].FieldName = 'CODE') then begin
AutoSearchFields[0].SearchExpression := IntToStr(Code);
end;
end;
end;
Olivier Peter.
there
e.g. Report.PrinterSetup.PrinterName := 'HP Laserjet 4050';
However when i turn set to True, it shows the name of the printer assigned
to the report at designtime.
(in this case: Default).If i select another printer in the Print Dialog then
it works just fine.
What i want to accomplish is that i don't need to show the PrintDialog, and
let the user choose from my program.
Olivier Peter.
receieves pages which have the printer setup already asisgned to them.
You'll have to assign the printer setup in the OnInitializePrinterSetup
event handler of the client report in order to change the printer setup.
--
Cheers,
Jim Bennett
Digital Metaphors
http://www.digital-metaphors.com
info@digital-metaphors.com
Thanks, Jim