Retaining Printer Properties set by User
Hi
By mistake I have just attached the question below to an old thread, rather
than creating this new thread. Sorry for the duplication.
In order to retain the printer settings when printing a batch of invoices
which use different templates, we have implemented the following code...
for j := 0 to number of invoices-1 do
begin
setup invoice, required template etc...
Template.LoadFromFile;
save pdf etc....
if j > 0 then //2nd invoice load printer settings from stream
begin
ppViewer1.Report.ShowPrintDialog := FALSE;
printerStream.Position := 0;
PrinterSetup.LoadDeviceSettingsFromStream(printerStream);
end;
print invoice etc.
if j > 0 then ppViewer1.Report.ShowPrintDialog := FALSE else
ppViewer1.Report.ShowPrintDialog
:= TRUE;
ppviewer1.Print;
//1st Invoice save printer settings to stream
if j = 0 then PrinterSetup.SaveDeviceSettingsToStream
(printerStream);
next invoice
end;
This works well if the printer used in the Print Dialog is the default
printer. If however the user changes the printer in the Print Dialog, the
1st document prints OK but subsequent documents fail with the error
"Windows cannot print due to a problem with the current printer setup. The
specified resource type cannot be found in the image file"
Advice greatfully received.
Philip L Jackson
By mistake I have just attached the question below to an old thread, rather
than creating this new thread. Sorry for the duplication.
In order to retain the printer settings when printing a batch of invoices
which use different templates, we have implemented the following code...
for j := 0 to number of invoices-1 do
begin
setup invoice, required template etc...
Template.LoadFromFile;
save pdf etc....
if j > 0 then //2nd invoice load printer settings from stream
begin
ppViewer1.Report.ShowPrintDialog := FALSE;
printerStream.Position := 0;
PrinterSetup.LoadDeviceSettingsFromStream(printerStream);
end;
print invoice etc.
if j > 0 then ppViewer1.Report.ShowPrintDialog := FALSE else
ppViewer1.Report.ShowPrintDialog
:= TRUE;
ppviewer1.Print;
//1st Invoice save printer settings to stream
if j = 0 then PrinterSetup.SaveDeviceSettingsToStream
(printerStream);
next invoice
end;
This works well if the printer used in the Print Dialog is the default
printer. If however the user changes the printer in the Print Dialog, the
1st document prints OK but subsequent documents fail with the error
"Windows cannot print due to a problem with the current printer setup. The
specified resource type cannot be found in the image file"
Advice greatfully received.
Philip L Jackson
This discussion has been closed.
Comments
Try this...
PrinterSetup.LoadDeviceSettingsFromStream(printerStream);
// clear printer specific configuration
PrinterSetup.DeviceSettings := 0;
TppPrinterSetup contains properties that can be used to configure any
printer. The one exception to this is DeviceSettings. RB 11 introduces
DeviceSettings to enable control over a printer's "proprietary" features. By
design, DeviceSettings is printer specific.
From the RBuilder help topic for TppPrinterSetup...
"Use the DeviceSettings property to configure a Printer's proprietary
features (print quality, color, stapler, etc.)"
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Thanks for the advice but all this seems to do is print one copy to the
selected printer and then all the subsequent prints are sent back to the
default printer.
On experimentation I have found the following to work....
for j := 1 to no_of_invoices do
begin
if j > 0 then
begin
ppViewer1.Report.ShowPrintDialog :=
FALSE;
printerStream.Position := 0;
PrinterSetup.PrinterName :=
MyPrinter;
PrinterSetup.LoadDeviceSettingsFromStream(printerStream);
end;
Print invoice etc...
if j = 0 then
begin
PrinterSetup.SaveDeviceSettingsToStream
(printerStream);
MyPrinter
:=MainDataModule.ppReport1.Printer.PrinterName;
end;
next Invoice
end;
Am I doing anything wrong by this?
Regards
Philip L Jackson
Glad to hear you got it working. That looks good. Set the PrinterName and
then LoadDeviceSettings.
--
Nard Moseley
Digital Metaphors
www.digital-metaphors.com
Best regards,
Nard Moseley
Digital Metaphors
www.digital-metaphors.com