Search code examples
delphiprintdialog

TPrintDialog and reading orientation parameter


Is there possibility to read from TPrintDialog orientation of page (horizontal/vertical) chosen by the user?

In classical solution:

if PrintDialog1.Execute() then
begin
  Printer.Orientation := poLandscape //I want read this parameter from PrintDialog

  Printer.BeginDoc;
  ...
  Printer.EndDoc;
end;

I can not find the orientation in TPrintDialog.


Solution

  • TPrintDialog does not offer that information. Rather it allows the user to select printer, print range, and number of copies.

    When you show a TPrintDialog the user has the option of setting properties for their selected printer, including page orientation. You are then expected to read that information out of the TPrinter object that you you use to perform the printing.

    Looking at your code, you are already using the global Printer object that represents the selected printer. This object already has the user's specified orientation. In other words, you can simply remove the line of code that attempts to assign to Printer.Orientation because that property has already been set.