如何取得打印纸张的大小?(100分)

用DocumentProperties这个api取得指定打印机的信息,里面包括打印纸张型号,页长页宽等
具体参见<a href="http://www.gislab.ecnu.edu.cn/DelphiBBS/DispQ.asp?LID=98048">
我想在程序中把cr3240的默认纸张A4改为US SF(或其它纸张),请教如何实现?</a>

别指望TPrinter.PageWidth和PageHeight, 那不准。
 
请看一下Inprise的回答。
Question and Answer Database

FAQ603D.txt Changing the papersize of a print job.
Category :Windows API
Platform :All
Product :All 32 bit

Question:
How can I change the papersize of my print job?


Answer:
One way to change printer settings at the start
of a print job is to change the printer's devicemode
structure.

See: TDEVMODE in the Delphi 1.02 help file or DEVMODE
in the Delphi 2.01 help file for other settings you can
change (providing the print driver supports the change).

The following example, contains code to change the papersize and
the paper bin that is used:

procedure TForm1.Button1Click(Sender: TObject);
var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDMode : THandle;
PDMode : PDEVMODE;
begin

Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(Device, Driver, Port, hDMode);
if hDMode <> 0 then
begin

pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin


{Set to legal}
pDMode^.dmFields := pDMode^.dmFields or dm_PaperSize;
pDMode^.dmPaperSize := DMPAPER_LEGAL;

{Set to custom size}
pDMode^.dmFields := pDMode^.dmFields or
DM_PAPERSIZE or
DM_PAPERWIDTH or
DM_PAPERLENGTH;
pDMode^.dmPaperSize := DMPAPER_USER;
pDMode^.dmPaperWidth := 100 {SomeValueInTenthsOfAMillimeter};
pDMode^.dmPaperLength := 100 {SomeValueInTenthsOfAMillimeter};

{Set the bin to use}
pDMode^.dmFields := pDMode^.dmFields or DMBIN_MANUAL;
pDMode^.dmDefaultSource := DMBIN_MANUAL;

GlobalUnlock(hDMode);
end;

end;

Printer.PrinterIndex := Printer.PrinterIndex;
Printer.begin
Doc;
Printer.Canvas.TextOut(100,100, 'Test 1');
Printer.EndDoc;
end;


7/16/98 4:31:28 PM
 
两个办法: 1, Escape( printer.handle, GETPHYSPAGESIZE, 0, nil, @physsize );可取得纸张的实际尺寸(点数,与打印机分辨率有关,把它转为
以Twips为单位就是实际尺寸)
2. pixelsperinchx := GetDeviceCaps( printer.handle, LOGPIXELSX );
Longint(printer.pagewidth) * 1440) div pixelsperinchx
可得到打印机可打印的范围尺寸(已转为Twips)。
 
补充一下:TPrinter.PageWidth和PageHeight取得的值绝对准确,只不过是与
打印机分辨率有关的打印机像素点为单位。
 
多人接受答案了。
 
顶部