DPI independent Print
Posted: Fri Feb 28, 2003 10:11 pm
Code updated for 5.20+
Restored from previous forum. Originally posted by Num3.
Well now you can put your text and gfx
with a mm accuracy on paper!!!
Don't forget this code is for A4, alter
the procedures for other paper sizes...
Here's the snippet 4 all
--
Kind Regards
Rui Carvalho
Old programmers never die... They branch into a subroutine...
Restored from previous forum. Originally posted by Num3.
Well now you can put your text and gfx
with a mm accuracy on paper!!!
Don't forget this code is for A4, alter
the procedures for other paper sizes...
Here's the snippet 4 all

Code: Select all
;****************************************
; Super Printer - DPI indepent print
; by Rui Carvalho - 2003
;
; Part of GIA - Lift Management Software
; Freeware
;****************************************
; mailto: rui-carvalho@bigfoot.com
; Original printer code by Fred
Declare ycm(x.f)
Declare xcm(x.f)
LoadFont(0, "Arial", ycm(0.4)) ;4mm font size
LoadFont(1, "Arial", ycm(1)) ;1 cm font size
If PrintRequester()
If StartPrinting("PureBasic Test")
If StartDrawing(PrinterOutput())
DrawingFont(FontID(0))
DrawText(xcm(15), xcm(5.5), "PureBasic Printer Test")
DrawingFont(FontID(1)) ;1 cm font size
DrawText(xcm(10), ycm(20), "PureBasic Printer Test 2")
If LoadImage(0, "Data\PureBasiclogo.bmp") ;The logo bitmap is bigger
ResizeImage(0, xcm(6), ycm(2)) ;resize image for 6cm by 2cm
DrawImage(ImageID(0), xcm(1), ycm(1)) ;draw image at 1cm by 1cm
Else
MessageRequester("", "2", 0)
EndIf
FrontColor(RGB(100, 100, 100))
Box(xcm(2), ycm(6), xcm(6), ycm(8)) ;draw a 4cm by 4cm square
StopDrawing()
EndIf
StopPrinting()
EndIf
EndIf
; **** the trick !!!! ****
Procedure xcm(x.f)
result = x * (PrinterPageWidth() / 21) ;21cm A4
ProcedureReturn result
EndProcedure
Procedure ycm(x.f)
result = x * (PrinterPageWidth() / 29.7) ;29,7cm A4
ProcedureReturn result
EndProcedure
; Tested with fineprintpdf in multiple DPI's
; and on Xerox DC440 laser printer
Kind Regards
Rui Carvalho
Old programmers never die... They branch into a subroutine...