Page 1 of 1
Getting printer page margin widths
Posted: Sat Aug 15, 2020 1:29 am
by DeanH
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
Posted: Sat Aug 15, 2020 7:39 am
by Olli
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.
Re: Getting printer page margin widths
Posted: Sat Aug 15, 2020 9:20 am
by DeanH
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.
Re: Getting printer page margin widths
Posted: Sat Aug 15, 2020 10:10 am
by DeanH
Got it! Maybe...
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
But this does not:
Code: Select all
B.q=PrintRequester()
Debug GetDeviceCaps_(B,#PHYSICALOFFSETX)
Debug GetDeviceCaps_(B,#PHYSICALOFFSETY)
This returns the correct margins:
Code: Select all
C.q=PrintRequester()
D.q=StartDrawing(PrinterOutput())
Debug GetDeviceCaps_(D,#PHYSICALOFFSETX)
Debug GetDeviceCaps_(D,#PHYSICALOFFSETY)
StopDrawing()
As does this:
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
Posted: Sat Aug 15, 2020 10:25 am
by Olli
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()
Re: Getting printer page margin widths
Posted: Tue Aug 18, 2020 6:11 pm
by collectordave
Had similar problems.
Did a print and preview module it is somewhere on the forum.
Does landscape as well.
CD