Question
“How can I get the printer’s default settings, such as the paper name?”
Solution
The Printer.DefaultPrinterSetup property provides access to the printer’s default settings. Here is an example that iterates over the installed printers and populates a list box with the printer name and default paper name.
Download: DefaultPrinterSetup.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 |
uses ppPrintr; procedure TForm1.Button1Click(Sender: TObject); var lPrinter: TppPrinter; liIndex: Integer; lsDescription: String; begin lPrinter := TppPrinter.Create; // iterate over installed printers // skip the first two entries (Default and Screen) for liIndex := 2 to ppPrinters.PrinterNames.Count-1 do begin lPrinter.PrinterName := ppPrinters.PrinterNames[liIndex]; // get the default paper name lsDescription := lPrinter.PrinterName + ': ' + lPrinter.DefaultPrinterSetup.PaperName; ListBox1.Items.Add(lsDescription); end; lPrinter.Free; end; |