Easy way to set printer output to landscape?

Just starting out? Need help? Post your questions and find answers here.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Easy way to set printer output to landscape?

Post 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.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Post by Rook Zimbabwe »

I was gonna tell you to turn the printer sideways but srod has a much better idea! :wink:

Thanks srod, I was wondering how to do this!
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

:lol:
I may look like a mule, but I'm not a complete ass.
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Post by Derek »

Thanks srod.
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Easy way to set printer output to landscape?

Post 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
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Easy way to set printer output to landscape?

Post 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.
I may look like a mule, but I'm not a complete ass.
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Easy way to set printer output to landscape?

Post 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 !!!
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
harkon
Enthusiast
Enthusiast
Posts: 217
Joined: Wed Nov 23, 2005 5:48 pm

Re: Easy way to set printer output to landscape?

Post by harkon »

my recommendation would be to use the printer lib
http://www.purebasicpower.de/?PrinterLib

It just makes things easier.
Missed it by that much!!
HK
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: Easy way to set printer output to landscape?

Post by srod »

Agreed, that is a nice lib.
I may look like a mule, but I'm not a complete ass.
User avatar
ar-s
Enthusiast
Enthusiast
Posts: 344
Joined: Sat Oct 06, 2007 11:20 pm
Location: France

Re: Easy way to set printer output to landscape?

Post 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.
~Ar-S~
My Image Hoster for PB users
My webSite (french) with PB apps : LDVMULTIMEDIA
PB - 3.x / 5.7x / 6 - W11 x64 - Ryzen 7 3700x / #Rpi4

Code: Select all

r3p347 : 7ry : un71l d0n3 = 1
Post Reply