delphi调用打印机打印Pdf格式文件

 use Vcl.Printers, Winapi.ShellAPI;

procedure
TForm1.PrintDocument(const documentToPrint: string); var printCommand: string; printerInfo: string; Device, Driver, Port: array[0..255] of Char; hDeviceMode: THandle; begin if Printer.PrinterIndex = ComboBox1.ItemIndex then begin printCommand := 'print'; printerInfo := ''; end else begin printCommand := 'printto'; Printer.PrinterIndex := ComboBox1.ItemIndex; Printer.GetPrinter(Device, Driver, Port, hDeviceMode); printerInfo := Format('"%s" "%s" "%s"', [Device, Driver, Port]); end; ShellExecute(0, PChar(printCommand), PChar(documentToPrint), PChar(printerInfo), nil, SW_NORMAL); end;

procedure TForm1.FormCreate(Sender: TObject);
begin
    ComboBox1.Items.Assign(Printer.Printers);  //本机所有的打印机
end;

 

posted @ 2022-06-21 21:54  夏天的西瓜君  阅读(2092)  评论(0编辑  收藏  举报