Getting printer page margin widths
- DeanH
- Enthusiast

- Posts: 284
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Getting printer page margin widths
I would like to use the vector drawing functions for printouts, and need to position output at specific places on a page measured by a ruler. One thing I cannot find is how to obtain the width of the margins imposed by the printer itself. I can do this with GetDeviceCaps_ but that requires a DC. Is there a way to obtain the DC or another way to read the margin size?
Re: Getting printer page margin widths
Hello,
you cannot do exactly the hardwared margins, because they are not ever centered. Just make a rule-tool, as a real rule : the zero is not exactly on the border of the tool, but a little bit shifted. And choose the drawing unit (pixel, inch
, cm) in the vector drawing library.
you cannot do exactly the hardwared margins, because they are not ever centered. Just make a rule-tool, as a real rule : the zero is not exactly on the border of the tool, but a little bit shifted. And choose the drawing unit (pixel, inch
, cm) in the vector drawing library.
- DeanH
- Enthusiast

- Posts: 284
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: Getting printer page margin widths
Years ago I used to be able to obtain the DC using:
Import ""
PB_Printer_DC As "_PB_Printer_DC"
EndImport
The DC was returned after DefaultPrinter() or PrintRequester(). That no longer works.
I have been using PrinterLib successfully since it came out but have run into a problem when compiling to 64-bit. My software prints to blank stick-on labels, both text and images, and precise location is needed. To do that I need to know the margins imposed by the printer. If I have the DC I can use GetDeviceCaps to work out the margins.
Import ""
PB_Printer_DC As "_PB_Printer_DC"
EndImport
The DC was returned after DefaultPrinter() or PrintRequester(). That no longer works.
I have been using PrinterLib successfully since it came out but have run into a problem when compiling to 64-bit. My software prints to blank stick-on labels, both text and images, and precise location is needed. To do that I need to know the margins imposed by the printer. If I have the DC I can use GetDeviceCaps to work out the margins.
- DeanH
- Enthusiast

- Posts: 284
- Joined: Wed May 07, 2008 4:57 am
- Location: Adelaide, South Australia
- Contact:
Re: Getting printer page margin widths
Got it! Maybe...
This seems to work:
But this does not:
This returns the correct margins:
As does this:
This seems to work:
Code: Select all
A.q=DefaultPrinter()
Debug GetDeviceCaps_(A,#PHYSICALOFFSETX) ;non printing left margin in pixels
Debug GetDeviceCaps_(A,#PHYSICALOFFSETY) ;non printing left margin in pixels
Code: Select all
B.q=PrintRequester()
Debug GetDeviceCaps_(B,#PHYSICALOFFSETX)
Debug GetDeviceCaps_(B,#PHYSICALOFFSETY)
Code: Select all
C.q=PrintRequester()
D.q=StartDrawing(PrinterOutput())
Debug GetDeviceCaps_(D,#PHYSICALOFFSETX)
Debug GetDeviceCaps_(D,#PHYSICALOFFSETY)
StopDrawing()
Code: Select all
B.q=PrintRequester()
C.q=PrinterVectorOutput(#PB_Unit_Millimeter)
D.q=StartVectorDrawing(C)
Debug GetDeviceCaps_(C,#PHYSICALOFFSETX)
Debug GetDeviceCaps_(C,#PHYSICALOFFSETY)
StopVectorDrawing()
It looks as if DefaultPrinter() may return the DC. PrintRequester only returns 0 or 1 but StartDrawing(PrinterOutput()) returns the DC as well. PrinterVectorOutput seems to as well. Tested on Canon, Epson, HP laserjet and Brother laser printer drivers.
Is this correct?
(Next problem is how to get landscape printing using vector drawing...)Re: Getting printer page margin widths
Interesting, even if I suppose it is only on Windows. You can maybe test, trying to use the both :
Code: Select all
PrintRequester()
DC.Q = DefaultPrinter()-
collectordave
- Addict

- Posts: 1310
- Joined: Fri Aug 28, 2015 6:10 pm
- Location: Portugal
Re: Getting printer page margin widths
Had similar problems.
Did a print and preview module it is somewhere on the forum.
Does landscape as well.
CD
Did a print and preview module it is somewhere on the forum.
Does landscape as well.
CD
Any intelligent fool can make things bigger and more complex. It takes a touch of genius — and a lot of courage to move in the opposite direction.