首页  编辑  

打印机的分辨率和在不同分辨率下打印

Tags: /超级猛料/Print.打印/   Date Created:

uses printers;

Windows下的打印分辨对打印程序有着至关重要的作用,如果你想知道

打印机的分辨率,请在程序中加入一行:ShowMessage('水平分辨率'+inttost

r(GetDeviceCaps(printer.Handle,LOGPIXELSX))+chr(13)+'垂直分辨率:'

+inttostr(GetDeviceCaps(printer.Handle,LOGPIXELSY)));结果就一目了

然了。

如何在不同的打印分辨率下面打印?

下面给出一个函数,在调用这个函数之后,你就可以使用Font.Size来设置字体的大小而与打印机分辨率无关了。

注意必须在Printer.BeginDoc之后调用这个函数!

{-------------------------------------------------------------

Sets the logical dots per inch for the printer and sets the printer axes to point RIGHT and DOWN.  Thus (0,0) is at the top left corner of the page. Returns the page size in logical coordinates.

Note:  Must be called AFTER Printer.BeginDoc.

--------------------------------------------------------------}

function SetPrinterScale(dpi : integer) : TPoint;

var

 DeviceDpiX, DeviceDpiY : integer;

begin

 with Printer do begin

   SetMapMode(Handle, MM_ISOTROPIC);

   SetWindowExt(Handle, dpi, dpi);

   DeviceDpiX := GetDeviceCaps(Handle, LOGPIXELSX);

   DeviceDpiY := GetDeviceCaps(Handle, LOGPIXELSY);

   SetViewPortExt(Handle, DeviceDpiX, DeviceDpiY);

   Result := Point(PageWidth, PageHeight);

   with Canvas do begin

     DPtoLP(Handle, Result, 1); { This API call is required... }

     Font.PixelsPerInch := DPI; { ...to make this work.  (Who knows why?)         }

   end;

 end;

end;