Board index » delphi » Printer margins ?

Printer margins ?

I need to place text and images very exact on the printers canvas.
I've noticed that when printing at 0,0 you get the printout not at the border
of the paper, but just inside/on the left and top margin.
This may vary from printer to printer, I guess, and as I'm developing a
program that will print on a different kind of printer, I'm in trouble...
I've experimented with different mapping modes, like MM_LOMETRIC and
MM_HIMETRIC, but they all seem to do handle the margins in the same way.

I need to find out exactly where the margins are!
How do you do that?

--
|| Bjorn K. Nilssen      // http://home.sn.no/~bjoernk/  // mainly 3D ||

 

Re:Printer margins ?


On 16 Oct 1997 15:35:37 +0200, bjoe...@sn.no (Bjorn-Kare Nilssen)
wrote:

Quote
>I need to place text and images very exact on the printers canvas.
>I've noticed that when printing at 0,0 you get the printout not at the border
>of the paper, but just inside/on the left and top margin.
>This may vary from printer to printer, I guess, and as I'm developing a
>program that will print on a different kind of printer, I'm in trouble...
>I've experimented with different mapping modes, like MM_LOMETRIC and
>MM_HIMETRIC, but they all seem to do handle the margins in the same way.

>I need to find out exactly where the margins are!
>How do you do that?

>--
>|| Bjorn K. Nilssen      // http://home.sn.no/~bjoernk/  // mainly 3D ||

Bjorn-

You can use the Printer Escape() commadn to ask the driver how big the
top and left margins are, and then use SetViewPortExt() to set the
origin at -1 * Topand  -1 * Left, so that location 0,0 becomes the
upper left corner of the paper. To get the margins, (and printable
width/height, you can use the following:

{ Determine non-printable region on form }
Function TForm1.GetPrinterMargins : TRect;
var
        pMarg:TPoint;
        nEscapeCode:Integer;
Begin
        pMarg := Point (0,0);
        GetPrinterMargins.TopLeft := Point (0,0);       { Default
margins to 0}
        nEscapeCode := GETPRINTINGOFFSET;
        if (Escape(Printer.Canvas.Handle, QUERYESCSUPPORT,
sizeof(Integer), @nEscapeCode, Nil) <> 0) then
        Begin
                if Escape(Printer.Canvas.Handle, GETPRINTINGOFFSET, 0,
Nil, @pMarg) > 0 then
                        GetPrinterMargins.TopLeft := pMarg;
        End;
        nEscapeCode := GETPHYSPAGESIZE;
        if (Escape(Printer.Canvas.Handle, QUERYESCSUPPORT,
sizeof(Integer), @nEscapeCode, Nil) <> 0) then
        Begin
                if Escape(Printer.Canvas.Handle, GETPHYSPAGESIZE, 0,
Nil, @pMarg) > 0 then
                        GetPrinterMargins.BottomRight := pMarg;
        End;

End;

Note that NT has an alternative method for getting the offsets (See
the Win32 API help file, GetDeviceCaps() call for NT's extensions to
the structure.

Good Luck!

David Block
dbl...@vdn.com

Re:Printer margins ?


Bjorn-Kare Nilssen <bjoe...@sn.no> wrote in article
<6RiR0gmCg0CS09...@sn.no>...

Quote
> I need to place text and images very exact on the printers canvas.
> I've noticed that when printing at 0,0 you get the printout not at the
border
> of the paper, but just inside/on the left and top margin.
> This may vary from printer to printer, I guess, and as I'm developing a
> program that will print on a different kind of printer, I'm in trouble...
> I've experimented with different mapping modes, like MM_LOMETRIC and
> MM_HIMETRIC, but they all seem to do handle the margins in the same way.

_________________________________________

aa := TPoint(Printer.PageWidth, Printer.PageHeight);
  returns the paper size.

Escape(Printer.Handle, GETPHYSPAGESIZE, 0, nil, @bb);
  returns a TPoint which gives the width and height of the printable page
area.

Escape(Printer.Handle, GETPRINTINGOFFSET, 0, nil, @cc);
  returns a TPoint which is the amount of unprintable left and top space.

Getting the exact location on the paper just means a little maths with
these TPoints. :)
_________________________________________

  ?  Leigh Harrison      
  ?  tel +64 6 343 2671
  ?  fax +64 6 343 2649
  ?  mobile 025 933 913
  ?  email le...@radiOshop.co.nz
  ?  3 Iris Place Wanganui New Zealand
_________________________________________
                             radiOshop

Re:Printer margins ?


In article <344626d2.3091...@news.nothingbutnet.net>,

Quote
dbl...@vdn.com (David Block) wrote:

>You can use the Printer Escape() commadn to ask the driver how big the

Thanks a lot !
That saved me :-)

--
|| Bjorn K. Nilssen      // http://home.sn.no/~bjoernk/  // mainly 3D ||

Other Threads