How To…Configure Printer Specific Settings

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:

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;