English 中文(简体)
忽略默认打印机设置
原标题:Default printer settings are ignored

使用 Windows 打印 Spoler API s, 我们可以打印 XPS 文件 。

问题是打印 < 坚固> pooler 忽略 的 < 坚固 > 默认打印机设置

(我们放弃了尝试 < a href=" https://stackoverflow.com/ questions/10345179/resetdc-does- nothing-print-spooler-apis- for- windows" @em> apply 打印机设置 。默认打印机设置将只需要足够。)

例如... 打印输出总是以彩色和每页一张纸的形式出来, 不论控制面板设置的设置是什么: 黑& amp; 白/ 彩色、 双双色/ 非双面、 每页多页/ 每页单页 。

其他应用程序, 如 MS Word 和 Adobe 尊重默认打印机设置 。

我们在使用德尔斐 XE2和Windows 7 64比特

这个测试代码是自封的, 所以你可以把它粘贴进去测试它...

弹出一个组合框, 使用打印机名称 :

uses
  Printers

ComboBox1.Items.Assign(Printer.Printers);

印刷程序:

uses
  Winapi.WinSpool

procedure PrintXPS(PrinterName, FileNameXPS: string; ParentFormHandle: THandle = 0);

  //  Printer handle

  procedure Printer_Open(out Printer: THandle; Defaults: PPrinterDefaultsW = nil);
  begin
    if  not OpenPrinterW(PWideChar(PrinterName), Printer, Defaults) then
      RaiseLastOSError;
  end;

  procedure Printer_Close(Printer: THandle);
  begin
    if  not ClosePrinter(Printer) then
      RaiseLastOSError;
  end;

  //  Print jobs

  function  JobCreate(Printer: THandle; FileName: string): Cardinal;
  var
    lBufferSize: Cardinal;
    lAddJobInfo: PAddJobInfo1W;
  begin
    //  Create job
    AddJobW(Printer, 1, nil, 0, lBufferSize);
    GetMem(lAddJobInfo, lBufferSize);
    try
      if  not AddJobW(Printer, 1, lAddJobInfo, lBufferSize, lBufferSize)  then
        RaiseLastOSError;
      Result  := lAddJobInfo.JobId;
      //  Copy the file into place
      CopyFile(PWideChar(FileName), lAddJobInfo.Path, True);
    finally
      FreeMem(lAddJobInfo, lBufferSize);
    end;
  end;

  procedure JobStart(Printer: THandle; JobID: Cardinal);
  begin
    if  not ScheduleJob(Printer, JobID) then
      RaiseLastOSError;
  end;

var
  PrinterA: THandle;
  JobID: Cardinal;
begin
  if  not FileExists(FileNameXPS)  then
    raise Exception.Create( File not found:   + FileNameXPS);

  Printer_Open(PrinterA, nil);
  try
    JobID := JobCreate(PrinterA, FileNameXPS);
    JobStart(PrinterA, JobID);
  finally
    Printer_Close(PrinterA);
  end;

end;
问题回答

我知道你不能改变.xps 文件的外观

XPS 代表 XML 纸张规格, 它实际上是一个“ 电子纸 ”, 屏幕上的文件 < 坚固 > 和打印就是作者的原意。 曾经经历过由于不同默认打印机而在共享计算机上办公室文件的页面布局变换的人, 都欣赏它。

编辑 编辑 编辑 编辑 编辑 编辑

测试测试测试

1.) 默认黑白打印机设置。打开. xps 文件打印 。

  • With IE == colored output.
  • With XPS Viewer EP == colored output.

<强度 > 默认打印机设置@ 忽略@ action: inmenu

2. 对话:手动制作打印机,印刷黑白两套。

  • IE == black and white output.
  • XPS Viewer EP == black and white output.




相关问题
determining the character set to use

my delphi 2009 app has a basic translation system that uses GNUGetText. i had used some win API calls to prepare the fonts. i thought it was working correctly until recently when someone from Malta ...

Help with strange Delphi 5 IDE problems

Ok, I m going nuts here. For the last (almost) four years, I ve been putting up with some extremely bad behavior from my Delphi 5 IDE. Problems include: Seemingly random errors in coride50.bpl ...

How to write a Remote DataModule to run on a linux server?

i would like to know if there are any solution to do this. Does anyone? The big picture: I want to access data over the web, using my delphi thin clients. But i´would like to keep my server/service ...

How convert string to integer in Oxygene

In Delphi, there is a function StrToInt() that converts a string to an integer value; there is also IntToStr(), which does the reverse. These functions doesn t appear to be part of Oxygene, and I can ...

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签