Board index » delphi » TPrinter I need millimeters

TPrinter I need millimeters

Hi All,

I'm trying to print mailing labels on a non standard sized form.
the Printer.PageHeight returns pixels. Is there anyway to operate in
millimeters instead?

I'm not sure of the logic behind this because the pixels returnes would
depend on the current print resolution.

Also is there anyway of dynamically setting up my custom page size with the
printer.

Any help greatly appreciated as I'm really lost on this.

TIA

John Trenton.

 

Re:TPrinter I need millimeters


Quote
John Trenton wrote:

> Hi All,

> I'm trying to print mailing labels on a non standard sized form.
> the Printer.PageHeight returns pixels. Is there anyway to operate in
> millimeters instead?

You can get the value for Pixels/Inch by calling GetDeviceCaps with the
LOGPIXELSX parameter.  For example:

Procedure Calc_Counts;
Begin
     counts := GetDeviceCaps(Printer.Handle, LOGPIXELSX);
End;

Quote
> Also is there anyway of dynamically setting up my custom page size with the
> printer.

Not sure what you mean by 'dynamically', but if you'd like your app to
be able to set a user-defined paper size for the currently selected
printer you will need to modify the dmPaperSize, dmPaperWidth and
dmPaperLength fields of the driver's DEVMODE structure.  As an example,
the following would set the current printer to use 11"x17" paper:

procedure set_paper;

var
   hdl          : Thandle ;
   pdevicemode   : pdevicemodea;
   Device, Driver, Port : array [0..255] of char ;

begin
   Printer.Getprinter(device,driver,port,hdl);
   Printer.Setprinter(device,driver,port,0);
   pdevicemode := globallock (hdl);
   with pdevicemode^ do begin
      dmpapersize := DMPaper_User;
      // Note: the following 2 values are in tenths of a millimeter
      dmPaperWidth := trunc (11.0*254.0);
      dmpaperlength := trunc (17.0*254.0);
      dmSpecVersion := DM_SPECVERSION;
      dmfields := dmfields or DM_PAPERSIZE or DM_PAPERLENGTH or
DM_PAPERWIDTH or DM_SPECVERSION;
   end;
   globalunlock (hdl);
end;

Hope this helps.
Dave

Re:TPrinter I need millimeters


Hi Dave,

Thanks a ton mate, you've solved my problem and given me valuable insight
into using the Get and SetPrinter functions.
I don't quite know why  this works:
    >   Var
    >    pdevicemode   : pdevicemodea;

Where is pdevicemodea declared?

Thanks Again.

John.

Re:TPrinter I need millimeters


Quote
John Trenton wrote:
> I don't quite know why  this works:
>     >   Var
>     >    pdevicemode   : pdevicemodea;

> Where is pdevicemodea declared?

John,

Which version of Delphi are you using?

Dave

Other Threads