Question
“How can I configure the printer’s proprietary settings, such as the print quality, stapler, color, etc?”
Solution
Use the Report.PrinterSetup.DeviceSettings property to configure a Printer’s proprietary features (print quality, color, stapler, etc.).
At design-time, use the Report Designer’s Object Inspector to select the PrinterSetup.DeviceSettings property. Next, press the Edit… button to display the Printer’s built-in properties dialog. Prior to closing the dialog press the OK button to save changes. This will cause the PrinterSetup.SaveDeviceSettings property to toggle to True.
The following example shows how to Edit, Save, and Load DeviceSettings at run-time.
Download: PrinterSetupDeviceSettings.zip
Sample Delphi code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
uses ppPrintr; procedure TForm1.FormCreate(Sender: TObject); begin FDeviceSettingsFileName := TppFileUtils.GetApplicationFilePath + 'DeviceSettings.bin'; FDeviceSettingsStream := TMemoryStream.Create; // intialize listbox with list of installed printers Listbox1.Items.Assign(ppPrinters.PrinterNames); Listbox1.Items.Delete(1); // delete 'Screen' entry Listbox1.ItemIndex := 0; end; procedure TForm1.FormDestroy(Sender: TObject); begin FDeviceSettingsStream.Free; end; procedure TForm1.btnEditClick(Sender: TObject); begin // edit device settings - this method displays the printer's built-in dialog // and saves any configurations you perform to the Report.PrinterSetup object ppReport1.PrinterSetup.EditDeviceSettings; end; procedure TForm1.btnSaveToStreamClick(Sender: TObject); begin // edit and save to stream if ppReport1.PrinterSetup.EditDeviceSettings then ppReport1.PrinterSetup.SaveDeviceSettingsToStream(FDeviceSettingsStream); end; procedure TForm1.btnSaveToFileClick(Sender: TObject); begin // edit and save to file if ppReport1.PrinterSetup.EditDeviceSettings then ppReport1.PrinterSetup.SaveDeviceSettingsToFile(FDeviceSettingsFileName); end; procedure TForm1.btnLoadFromStreamClick(Sender: TObject); begin // load from stream if FDeviceSettingsStream.Size > 0 then begin FDeviceSettingsStream.Position := 0; ppReport1.PrinterSetup.LoadDeviceSettingsFromStream(FDeviceSettingsStream); end; end; procedure TForm1.btnLoadFromFileClick(Sender: TObject); begin // load from file if FileExists(FDeviceSettingsFileName) then ppReport1.PrinterSetup.LoadDeviceSettingsFromFile(FDeviceSettingsFileName); end; procedure TForm1.btnRestoreDefaultClick(Sender: TObject); begin // restore default settings ppReport1.PrinterSetup := ppReport1.Printer.DefaultPrinterSetup; end; procedure TForm1.ListBox1Click(Sender: TObject); begin ppReport1.PrinterSetup.PrinterName := ListBox1.Items[ListBox1.ItemIndex]; end; |