默认打印机设置将被忽略 [英] Default printer settings are ignored
问题描述
使用Windows Print Spooler API,我们可以打印XPS文件.
Using Windows Print Spooler API's, we can print out XPS files.
问题是打印后台打印程序会忽略 默认打印机设置.
(我们已经放弃尝试 应用打印机设置.默认打印机设置就足够了.)
(We've given up on trying to apply printer settings. Default printer settings will just have to suffice.)
例如...打印输出始终以彩色显示,每页打印在一张纸上,而不管控制面板中的设置是什么.白色/彩色,双面/非双面,每张纸多页/每张纸单页.
For example... the printouts always come out in colour and on one paper per page, regardless of what the settings are set to in the control panel: black & white/colour, duplex/not duplex, multiple pages per sheet/single page per sheet.
MS Word和Adobe等其他应用程序都遵循默认打印机设置.
Other applications such as MS Word and Adobe respect the default printer settings.
我们正在使用Delphi XE2和64位Windows 7.
We're using Delphi XE2 and Windows 7 64-bit.
此测试代码是自包含的,因此您只需将其粘贴以对其进行测试...
This test code is self contained, so you can just paste it in to test it...
使用以下命令用打印机名称填充组合框:
Populate a combo box with printer names using:
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文件的外观.
Much as I know you can not change the appearance of a .xps file.
XPS代表XML Paper Specification,它实际上是一种电子纸",在屏幕上显示的文档和作者所打算的完全一样.曾经经历过,由于默认打印机不同而在共享计算机上的Office文档的页面布局如何发生变化的任何人,都应该感激不已.
XPS stands for XML Paper Specification, it is virtually an "electronic paper", the document on screen and in print is exactly the way it was intended by the author. Anyone who has ever experienced, how the page layout of an Office document on a shared computer because of a different default printer has shifted, appreciate it.
编辑
测试
1.)黑白打印机默认设置.打开. xps文件打印.
1.) Default black and white printer settings. Open the. xps file Print.
- 使用IE ==彩色输出.
- 使用XPS Viewer EP ==彩色输出.
默认打印机设置==已忽略.
2.)对话框:手动设置打印机以打印黑白设置.
2.) Dialog: Printer-settings manually to print black and white set.
- IE ==黑白输出.
- XPS Viewer EP ==黑白输出.
这篇关于默认打印机设置将被忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!