Page 1 of 1
Easy way to set printer output to landscape?
Posted: Sun Feb 03, 2008 12:08 pm
by Derek
Is there a straight forward way to set the printer output to landscape without having to use loads of code to achieve it, just a simple api call or do you have to set up the printer using api calls etc and bypass the PB printer routines.
If not then perhaps it could be added to the command set, maybe a setprinteroutput() to change the rotation.
Posted: Sun Feb 03, 2008 1:44 pm
by srod
Easy enough, though it can be a little fiddly at times.
The following code will print two pages to your default printer; the first in portrait and the second in landscape. Ideally this code should be combined with the use of a Windows print dialogue etc. (that's where it gets fiddly!)
Code: Select all
STDPrinterName$ = Space(260)
GetPrivateProfileString_("WINDOWS","DEVICE","", @STDPrintername$, 260, "Win.Ini")
STDPrintername$ = StringField(STDPrintername$, 1,",")
PrinterHandle.l = 0
OpenPrinter_(StdPrintername$,@PrinterHandle.l,0)
Dim DevIn.DEVMODE(0)
Dim DevOut.DEVMODE(0)
DocumentProperties_(0,Printerhandle,StdPrintername$,DevIn(0),DevOut(0),#DM_OUT_BUFFER|#DM_IN_BUFFER)
ClosePrinter_(PrinterHandle)
DevIn(0)\dmOrientation = 2; Landscape.
PrinterDC.l = CreateDC_("WINSPOOL",StdPrintername$,0,0)
DocInf.DOCINFO
DocInf\cbSize = SizeOf(DOCINFO)
DocInf\lpszDocName = @"Portrait to Landcsape"
DocInf\lpszOutput = #Null
If StartDoc_(PrinterDC,@DocInf) > 0
If StartPage_(PrinterDC) > 0
TextOut_(PrinterDC,300,0,"Tally bally ho (portrait!)",26)
EndPage_(PrinterDC)
EndIf
ResetDC_(PrinterDC, DevIn(0)) ;Switch to landscape.
If StartPage_(PrinterDC) > 0
TextOut_(PrinterDC,300,0,"Tally bally ho (landscape!)",27)
EndPage_(PrinterDC)
EndIf
EndDoc_(PrinterDC)
EndIf
The code is based on some from Andreas.
Posted: Sun Feb 03, 2008 3:09 pm
by Rook Zimbabwe
I was gonna tell you to turn the printer sideways but srod has a much better idea!
Thanks srod, I was wondering how to do this!
Posted: Sun Feb 03, 2008 4:04 pm
by srod
Posted: Sun Feb 03, 2008 7:12 pm
by Derek
Thanks srod.
Re: Easy way to set printer output to landscape?
Posted: Wed Oct 21, 2009 8:58 pm
by ar-s
Nice work,
But how could you apply this code to print a Picture ?
For xample in here
Code: Select all
;PB 4.30
#Image=10
;(...) my code
;Loop Event (..)
Case #Imprim
CatchImage(#Image,img)
LargImage = ImageWidth(#Image) : HautImage = ImageHeight(#Image)
If LargImage>HautImage
FormatImage$="landscape"
ResizeImage(#Image,3189,2244,#PB_Image_Smooth)
Else
FormatImage$="portrait"
ResizeImage(#Image,2244,3189,#PB_Image_Smooth)
EndIf
DetectImprim=DefaultPrinter()
If DetectImprim=0
MessageRequester ("Erreur","No Printer !",#MB_ICONEXCLAMATION)
Else
If StartPrinting("LDVM Printer")
If StartDrawing(PrinterOutput())
If FormatImage$="portrait"
DrawImage(ImageID(#Image), 50, 50)
ElseIf FormatImage$="landscape"
; How could i adapt your code in here ?
DrawImage(ImageID(#Image), 50, 50)
EndIf
StopDrawing()
Else
MessageRequester ("Erreur","Error !",#MB_ICONEXCLAMATION)
EndIf
StopPrinting()
EndIf
EndIf
thanks for help
Re: Easy way to set printer output to landscape?
Posted: Wed Oct 21, 2009 9:22 pm
by srod
If you are using a PB Print requester then you are pretty much out of luck because there is no way of retrieving the resulting DEVMODE structure in order to determine the user's selections etc.
You're better off using api and then adapting the code given above.
Note though that my code above is flawed. I can post a corrected version if you need, but I haven't time to convert your code to api.
Re: Easy way to set printer output to landscape?
Posted: Wed Oct 21, 2009 10:28 pm
by ar-s
I absolutly don't want to use a printrequester(), because the software have to work in different places with differents people, so i don't want people get acces to printer parameters.
I can post a corrected version if you need, but I haven't time to convert your code to api.
When you'll have the time, i'll be very happy to see your new code.
thanks.
Soon PB in 4.40 and no printer mode to choose landscape or portrait ! it's to bad !!!
Re: Easy way to set printer output to landscape?
Posted: Wed Oct 21, 2009 10:38 pm
by harkon
my recommendation would be to use the printer lib
http://www.purebasicpower.de/?PrinterLib
It just makes things easier.
Re: Easy way to set printer output to landscape?
Posted: Thu Oct 22, 2009 10:25 am
by srod
Agreed, that is a nice lib.
Re: Easy way to set printer output to landscape?
Posted: Thu Oct 22, 2009 11:24 am
by ar-s
Nice lib, i have try it and it's very usefull !
I can now print in both portrait and landscape, i just have some problems to resize "on the fly" with good ratio the pictures.
they have to be print in almost all the paper.