unit PdfPrint;

{$I ..\..\..\Lib\PDFlibDefines.inc}

interface

Uses
{$IFDEF XE2+}
  Winapi.Windows,
  System.Classes,
  System.SysUtils,
  Vcl.Controls,
  Vcl.StdCtrls,
  Vcl.Forms,
  Vcl.Dialogs,
  Vcl.Graphics,
  Vcl.ExtCtrls,
{$ELSE}
  Windows,
  Classes,
  SysUtils,
  Controls,
  StdCtrls,
  Forms,
  Dialogs,
  Graphics,
  ExtCtrls,
{$ENDIF}
  PDFlibrary;

Type
  TForm1 = Class(TForm)
    Button1: TButton;
    Button2: TButton;
    Procedure Button1Click(Sender: TObject);
    Procedure Button2Click(Sender: TObject);
  Private
    { Private declarations }
  Public
    { Public declarations }
  End;

Var
  Form1: TForm1;

Implementation

{$R *.dfm}

Procedure TForm1.Button1Click(Sender: TObject);
Var
  PDFlib: TPDFlib;
Begin
  PDFlib := TPDFlib.Create;
  Try
    Begin
      ShowMessage(PDFlib.GetDefaultPrinterName);
    End;
  Finally
    PDFlib.Free;
  End;
End;

Procedure TForm1.Button2Click(Sender: TObject);
Var
  PDFlib: TPDFlib;
  CustPrinter: WideString;
  PrintOpt: Integer;
Begin
  PDFlib := TPDFlib.Create;
  Try
    With PDFlib Do
    Begin
      LoadFromFile('PageSample.pdf', '');
      CustPrinter := NewCustomPrinter(GetDefaultPrinterName);

      SetupPrinter(CustPrinter, 1, 1);
      // https://docs.microsoft.com/en-us/windows/desktop/intl/paper-sizes  1=DMPAPER_LETTER

      If SetupPrinter(CustPrinter, 11, 1) = 1 Then
      // (CustomPrinterName: WideString; Setting 11 = Orientation, NewValue:1 = portrait)
      Begin
        PrintOpt := PrintOptions(0, 0, 'A4 Portrait Page');
        // PrintOptions(PageScaling 0=None, AutoRotateCenter: 0; Title: title used by Windows)
        PrintDocument(CustPrinter, 1, 1, PrintOpt);
        // PrintDocument(PrinterName: WideString; StartPage, EndPage, Options)
      End;
      If SetupPrinter(CustPrinter, 11, 2) = 1 Then
      // (CustomPrinterName: WideString; Setting 11 = Orientation, NewValue:2 = landscape)
      Begin
        PrintOpt := PrintOptions(0, 0, 'A4 Landscape Page');
        PrintDocument(CustPrinter, 2, 2, PrintOpt);
      End;
    End;
  Finally
    PDFlib.Free;
  End;
End;

End.
