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

2022/6/21 23:23:51

本文主要是介绍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;

 



这篇关于delphi调用打印机打印Pdf格式文件的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程