Delphi: How to print a PDF without showing it?

后端 未结 4 1492
隐瞒了意图╮
隐瞒了意图╮ 2020-12-08 16:23

I have been looking online for some time now, but I still haven\'t figured out how to print a PDF file in Delphi without showing the document itself, or a print dialog. I ju

4条回答
  •  情歌与酒
    2020-12-08 17:20

    Printing a PDF to a printer without attempting to use Adobe Reader from Delphi can be done using Debenu Quick PDF Library, which supports all versions of Delphi from 4 to XE8. Sample code for printing a PDF programmatically without previewing it first:

    procedure TForm6.PrintDocumentClick(Sender: TObject);
    var
    iPrintOptions: Integer;
    begin
      DPL := TDebenuPDFLibrary1115.Create;
      try
        UnlockResult := DPL.UnlockKey('...'); // Add trial license key here
        if UnlockResult = 1 then
          begin
              // Load your file
              DPL.LoadFromFile('test.pdf', '');
    
              // Configure print options
              iPrintOptions := DPL.PrintOptions(0, 0, 'Printing Sample');
    
              // Print the current document to the default printing
              // using the options as configured above
              DPL.PrintDocument(DPL.GetDefaultPrinterName(), 1, 1, iPrintOptions);
          end;
        finally
        DPL.Free;
      end;
    end;
    

    More advanced printing options are also available using the customer printer functions. It's not a free SDK, but it will do exactly what you want.

提交回复
热议问题