+ -
当前位置:首页 → 问答吧 → 如何取得当前打印机所用的纸张Form名称?

如何取得当前打印机所用的纸张Form名称?

时间:2011-10-11

来源:互联网

如下可取得印表机所有纸张格式名称:

procedure GetPrinterPapers(vStrs: TStrings);
var
  Device, Driver, Port: array[0..255] of Char;
  hDevMode: THandle;
  j, numPaperformats: Integer;
  pPaperFormats: PPapernameArray;
  vPrinter: TPrinter;
begin
  vPrinter := TPrinter.Create;
  vPrinter.PrinterIndex := -1;
  vPrinter.GetPrinter(Device, Driver, Port, hDevmode);
  numPaperformats :=
  WinSpool.DeviceCapabilities(Device, Port, DC_PAPERNAMES, nil, nil);
  if numPaperformats > 0 then
  begin
  GetMem(pPaperformats,
  numPaperformats * Sizeof(TPapername));
  vStrs.clear;
  try
  WinSpool.DeviceCapabilities
  (Device, Port, DC_PAPERNAMES,
  Pchar(pPaperFormats), nil);
  for j := 1 to numPaperformats do
  vStrs.add(pPaperformats^[j]);
  finally
  FreeMem(pPaperformats);
  end;
  end;
end;


但我该如何取得当前印表机选的纸张格式名称是A4、B5、自订或其它的自订名例如"测试" ?
目前只有想到遍历每一种纸张取得其大小,如果和当前印表机纸张大小符合即可能是当前选中项目,
但这有一个问题就是假使有2种自定义纸张叫"自定义1"、"自定义2",且它们的纸张大小都设成相同,
此时便无法判断当前选择的是哪一个了?
是否有其他方式或API可以直接取得的呢?谢谢

作者: dkjfsoman   发布时间: 2011-10-11

或是请问如何跳过PrintDialog的画面
直接开启印表机驱动所提供的设定页面? 
例如Foxit Reader它的列印介面就不是用Windows的Dialog
进去后点Properties可以显示印表机驱动的设定页
那个Properties按钮所做的事如何实现?

作者: dkjfsoman   发布时间: 2011-10-11