Page 1 of 1

DPI independent Print

Posted: Fri Feb 28, 2003 10:11 pm
by BackupUser
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 :)

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...

Posted: Mon Mar 03, 2003 8:21 am
by BackupUser
Restored from previous forum. Originally posted by searhin.

Num3
i think that's a nice one. i was about to add a printing routine to my app anyway so i tried your structures. found it's very comfortable to use and easily gives the expected results!

Posted: Mon Mar 03, 2003 9:03 pm
by BackupUser
Restored from previous forum. Originally posted by Num3.
Originally posted by searhin

Num3
i think that's a nice one. i was about to add a printing routine to my app anyway so i tried your structures. found it's very comfortable to use and easily gives the expected results!
Thanks :)

I'll be releasing a full printpreview and print code soon (print being the same from this snippet) , so keep looking at the forums...




--
Kind Regards
Rui Carvalho

Old programmers never die... They branch into a subroutine...

Posted: Sat Mar 15, 2003 9:21 am
by BackupUser
Restored from previous forum. Originally posted by Num3.

Here's the link to the other topic:

viewtopic.php?t=5388

enjoy

--
Kind Regards
Rui Carvalho

Old programmers never die... They branch into a subroutine...

Posted: Fri Feb 06, 2004 11:11 am
by Passant
I've got another question to that topic. I've you use this code there is a little problem to integrate the printerrequester in your application because the user can change the format to A5 and so on and than the printed result is in another size than you print the same on A4.
But what can I do to print on all formats exactly?

Posted: Mon Feb 09, 2004 10:01 pm
by Num3
Hi Passant,

That's not a really easy task...

1. You need to know which size was selected by the user
2. You need to make a table of conversion

Code: Select all

If A4 : width=21 :height = 29.7 : endif
If A5 : width=21 :height = 14.85 : endif

etc...
etc...
3. Change my code to use variable page size instead of fixed size

Code: Select all

Procedure xcm(x.f)

result = x * (PrinterPageWidth()/width) 
ProcedureReturn result

EndProcedure


Procedure ycm(x.f)

result = x * (PrinterPageheight()/height) 
ProcedureReturn result

EndProcedure

4. Correct the bug i've found today :oops:


Procedure ycm(x.f)

result = x * (PrinterPageWidth()/29.7)
should be: result = x * (PrinterPageheight()/29.7)
ProcedureReturn result

EndProcedure

Posted: Mon Feb 09, 2004 11:02 pm
by Passant
Thank you for the answer first of all. It really seems to be a problem with very unconfortable solutions. Maybe it is much more easyer to solve my problem on a completely other way.

Re: DPI independent Print

Posted: Sun Sep 13, 2015 4:40 am
by collectordave
Another old thread.

The new vector drawing routines in PB 5.4 have made printing a fairly eay task.

Check out prinr and print preview topic.

This is DPI independent etc and prints in landscape when required and will also accept paper sizes a printer can support. Still being developed but almost there. Also shows a preview of what you want to print.

Hope this helps anyone else looking for this.