0 0 Votes

Delphi/Lazarus: Show and Change Printers

Info by Delphian | 13/06/2016 at 15:01

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

Avatar AuthorThe author has not added a short description to his profile yet.
Show Profile | Message

 

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 articles on askingbox.com. How to do.