11 Vote

Delphi/Lazarus: Show and Change Printers

Info by Delphian | Last update on 2023-01-29 | Created on 2016-06-13

In this tutorial, I would like to show you how you were able to create a list of all available printers and how to change the printer for printing out your documents using Delphi or Lazarus.

To make it work, you have to add the unit "printers" to your USES section.

Show available Printers

You can find a list of all printers that are currently available in:

printer.printers

Because printer.printers is just a normal string list (TStringList), you can easily go through the list using a normal loop, for example for adding the printers to a ComboBox for selection.

Read out default Printer

The default printer is always preset in printer.printers. Its index can be read out via printer.printerindex:

printer.printers[printer.printerindex]

You are just accessing the stringlist via the corresponding index.

Change Printer

In order to select another printer for printing, you can use the following commands:

printer.printers.IndexOf('Printer Name')

// or

printer.setprinter('Printer Name');

Of course, the name "Printer Name" should be one of the names from the list of the available printers, otherwise it is not working.

ReplyPositiveNegative

About the Author

AvatarThe author has not added a profile short description yet.
Show Profile

 

Related Topics

Important Note

Please note: The contributions published on askingbox.com are contributions of users and should not substitute professional advice. They are not verified by independents and do not necessarily reflect the opinion of askingbox.com. Learn more.

Participate

Ask your own question or write your own article on askingbox.com. That’s how it’s done.