Delphi:使用页面/打印机设置(如边距)打印html文件

时间:2019-05-09 15:12:06

标签: html delphi printing margin page-setup

我试图将打印HTML文件添加到有助于Web应用程序的应用程序中,通常用户通常以html或pdf格式保存来自Web应用程序的报告,并稍后再从我的应用程序中打印这些文件。 我发现以下使用shellexecute从Delphi打印HTML文件的方法:

uses
  Printers, shellapi;
....

var
  hDeviceMode: THandle;
  sDevice : array[0..255] of char;
  sDriver : array[0..255] of char;
  sPort   : array[0..255] of char;
  S, htmlFileName: String;
  shellResult: Integer;
begin
  htmlFileName := 'C:\users\steve\desktop\print.html';
  Printer.PrinterIndex := -1;
  Printer.GetPrinter(sDevice, sDriver, sPort, hDeviceMode);

  S := Format('"%s" "%s" "%s" "%s"', [htmlFileName, sDevice, sDriver, sPort]);
  S := 'c:\windows\system32\mshtml.dll,PrintHTML ' + S;
  shellResult := ShellExecute(Handle, 'open',PChar('rundll32.exe'),PChar(s),nil,SW_SHOWDEFAULT);
end;

首先,它应直接打印文件而不打开打印对话框,但不会。

第二,在打印文件之前,我找不到更改打印机或页面设置(例如纸张尺寸-页边距)的方法。

有没有一种方法可以在打印之前设置打印和纸张设置,或者还有另一种打印方法? 注意:我们可以更改文件格式并处理PDF文件。

最好的成绩,谢谢。

0 个答案:

没有答案