Printer Object: How to print "portrait" and "landscape" on the same page?

  • Permalink
  • submit to reddit
  • Email
  • Follow


Hi,

hope there's a simple solution to this.
If so, I'd appreciate a short hint.

I'm trying to find out how to change the printing
directions for special lines.

Simple example:
I need to print a line from left to right and
another line from bottom to top on the same page.


It's supposed to look like this page
(imagine the bottom to top letters
to be turned 90=B0 to the left)

#############################
#                           #
#  d                        #
#  l                        #
#  r                        #
#  o                        #
#  w                        #
#                           #
#  o                        #
#  l                        #
#  l                        #
#  e                        #
#  hello world              #
#                           #
#############################

I tried

Printer.NewPage
Printer.CurrentY =3D 1000
Printer.CurrentX =3D 1000
Printer.Font.Name =3D "Arial"
Printer.Orientation =3D 1
Printer.Print "hello world"
Printer.CurrentY =3D 1000
Printer.CurrentX =3D 1000
Printer.Orientation =3D 2
Printer.Print "hello world"
Printer.EndDoc

This fails - I can't change Orientation within the document.

I'm using Visual Basic 4 - but also could use
Visual Basic 6 if necessary.

Any hints?

Regards,
Daniel

0
Reply bbc (3) 1/25/2005 8:45:58 AM

See related articles to this posting

"Daniel Jolt" <bbc@myway.com> wrote in message 
news:1106642758.525938.160330@z14g2000cwz.googlegroups.com...

> I need to print a line from left to right and another line from
> bottom to top on the same page. I'm using Visual Basic 4 -
> but also could use Visual Basic 6 if necessary.

In order to print rotated text to the VB printer object you need to create a 
rotated font. After you have created your rotated font you cannot use any of 
the Printer Object methods or access any of its properties (including its 
hDC property) or it will immediately "forget" the rotated font that you 
created. So, you need to print your text using the TextOut API. You also 
need to get the Printer.hDC and save it to a standard VB variable (Long) 
*before* you create the font and you need to use the "saved" hDC with the 
TextOut API, instead of Printer.hDC.

Try the following code. It will certainly work in VB5 and VB6, but I'm not 
sure about VB4. I think it might work in VB4, but even if it doesn't it 
should be possible for you to modify it slightly so that it does. Note that 
the Printer.CurrentX and Printer.CurrentY properties are not altered to new 
positions after the text has been printed (that is the standard behaviour of 
the TextOut API) so you will need to position each line of text on your 
page. You could always modify the code so that it does automatically do the 
standard "vbCrLf" thing after printing, but I prefer it as it is.

Also note that I have written the RotatedText routine as a simple "one off" 
text printing code just so that you can easily see what is going on. In many 
cases, of course, this is wasteful (in terms of time)because your rotated 
font is created and then destroyed each time you call the routine. So, if 
you wanted to print (say) twelve lines of text one after the other all 
rotated to the same angle then a rotated font would be created and destroyed 
twelve times. A far better way would be to create the rotated font just once 
(before you print the first of the twelve lines) and then destroy it only 
after you have printed the twelfth. I'm sure that you will be able to modify 
it to behave in that way if you wish. It will still work of course exactly 
as I have posted it, and the "wasted" time probably isn't a lot when 
compared to the very slow hardware response of the printer, but I just 
though I'd mention it to you.

Mike

Option Explicit
Private Const LF_FACESIZE = 32
Private Type LOGFONT
    lfHeight As Long
    lfWidth As Long
    lfEscapement As Long
    lfOrientation As Long
    lfWeight As Long
    lfItalic As Byte
    lfUnderline As Byte
    lfStrikeOut As Byte
    lfCharSet As Byte
    lfOutPrecision As Byte
    lfClipPrecision As Byte
    lfQuality As Byte
    lfPitchAndFamily As Byte
    lfFaceName As String * LF_FACESIZE
End Type
Private Declare Function CreateFontIndirect Lib "gdi32" _
Alias "CreateFontIndirectA" (lpLogFont As LOGFONT) As Long
Private Declare Function SelectObject Lib "gdi32" _
(ByVal hdc As Long, ByVal hObject As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" _
(ByVal hObject As Long) As Long
Private Declare Function TextOut Lib "gdi32" Alias _
"TextOutA" (ByVal hdc As Long, ByVal x As Long, ByVal _
y As Long, ByVal lpString As String, ByVal nCount _
As Long) As Long

Private Sub RotatedText(textstring As String, angle As Long)
' Prints rotated text at the current printer x and y
' coordinates at a specified angle (in tenths of a degree
' in an anti clockwise direction (zero is normal text)
Dim MyHdc As Long
Dim oldmode As Long, xpix As Long, ypix As Long
Dim log_font As LOGFONT
Dim new_font As Long, old_font As Long
With Printer
  xpix = .ScaleX(.CurrentX - .ScaleLeft, .ScaleMode, vbPixels)
  ypix = .ScaleY(.CurrentY - .ScaleTop, .ScaleMode, vbPixels)
MyHdc = .hdc ' get the Printer.hDC and save it to a variable
End With
With log_font
 .lfEscapement = angle
 .lfHeight = (Printer.Font.Size * -20) / Printer.TwipsPerPixelY
 .lfFaceName = Printer.Font.Name & vbNullChar
 If Printer.Font.Bold = True Then
  .lfWeight = 700
 Else
  .lfWeight = 400
 End If
  .lfItalic = Printer.Font.Italic
  .lfUnderline = Printer.Font.Underline
 End With
new_font = CreateFontIndirect(log_font)
old_font = SelectObject(MyHdc, new_font)
TextOut MyHdc, xpix, ypix, textstring, Len(textstring)
SelectObject MyHdc, old_font
DeleteObject new_font
End Sub

Private Sub Command1_Click()
Dim angle As Long, s1 As String
Printer.ScaleMode = vbInches
Printer.Font.Name = "Times New Roman"
Printer.Font.Size = 14
' always start every print job with a simple Print statement
Printer.Print
Printer.CurrentX = 0
Printer.CurrentY = 4
s1 = "Hello World"
angle = 0 ' standard (no rotation)
RotatedText s1, angle
angle = 900 ' 90 degrees anticlockwise rotation
RotatedText s1, angle
Printer.EndDoc
End Sub





0
Reply mike5607 (1952) 1/25/2005 10:25:29 AM

>Try the following code. It will certainly work in VB5 and VB6, but I'm
not
>sure about VB4.

I tried this with VB4 and it works.
Thank's for posting such detailed instructions, Mike.

0
Reply bbc (3) 1/25/2005 11:02:18 AM
comp.lang.basic.visual.misc 10132 articles. 0 followers. Post

2 Replies
108 Views

Similar Articles

[PageSpeed] 29

  • Permalink
  • submit to reddit
  • Email
  • Follow


Reply:

Similar Artilces:

Printer Object: How to print "portrait" and "landscape" on the same page?
Hi, hope there's a simple solution to this. If so, I'd appreciate a short hint. I'm trying to find out how to change the printing directions for special lines. Simple example: I need to print a line from left to right and another line from bottom to top on the same page. It's supposed to look like this page (imagine the bottom to top letters to be turned 90=B0 to the left) ############################# # # # d # # l # # r # # o # # w ...

Splitting 2 pages/page landscape postscript file into two single page portrait pages
Hi, I am a newbie. I have a book.ps file which has all the pages, having two facing pages per portrait page like this: +---------------+--------------+ | | | | | | +---------------+--------------+ I want to split the two pages. I dont want to scan the pages and then make bulky images out of compact pdf file. The file was generated from a dvi and latex that are no longer available. The author has died. The ps was made to save the number of printed pages in an era before pdf. So there are two problems: (1) split the ps into single p...

Landscape Page among Portrait pages in Latex
Hi, How can I include/create a 'landscape' page among standard portrait pages? Suppose I have a big figure which I need to dedicate a 'landscape' page for it... Is there any package that allows us to do that? -- Regards, Edward WIJAYA SINGAPORE "Edward WIJAYA" <ewijaya@singnet.com.sg> writes: >Hi, >How can I include/create a 'landscape' page among standard portrait pages? >Suppose I have a big figure which I need to dedicate a 'landscape' page >for it... >Is there any package that allows us to do that? Have you looked at...

print
Hi we have an intranet site with a print function. We generate a "print friendly" version of a page, and the user can click a "print" button, which causes the javascript "print()" function to be called. Is it possible to allow the user to select whether the printout should be in portrait or landscape? I have seen examples on the web which set landscape - but this appears to be a global setting (so it will always be landscape). We would like to allow the user to check a checkbox or something - so they can decide at runtime if they print in portrait or landscape. ...

InDesign landscape and portrait pages
I want to have one landscape page and one portrait page. I had hoped to do it by having two masters but I can't figure out how to set the page orientation for anything except the whole document. In article <e43ain$qsb$1@sunburst.ccs.yorku.ca>, James <ask@me.com> wrote: > I want to have one landscape page and one portrait page. > I had hoped to do it by having two masters but I can't figure out how to > set the page orientation for anything except the whole document. You can't. Orientation is by document. On 5/12/06 7:51 PM, "James" wrote: >...

printing in landscape and portrait mode
Hi everyone.... &nbsp; In my application i have print option.I have given a combo box to select print orientation. &nbsp; In my code,i have used the vi's property print.orientation and i have set it to different as users choice. &nbsp; But the graph looks similar in all print outs despite of the mode selected by the user. &nbsp; Is there any way to rectify this? &nbsp; &nbsp; Thanks..... &nbsp; &nbsp; Thanks sir,for ur reply. &nbsp; What i was trying to do is just to print the graph differently taking the same parameter(for example,in MS Word we can tak...

Portrait and Landscape page orientation
Hi, I am intersted in having two different page orientations (portrait and landscape) on the same WORD file - landscape for longer tables, portrait for text and smaller tables. How can I do this? So far I am just using two separate WORD files. Page settings from File menu seems to affect the whole document. Thank you See my reply to your question about "Automatic numbering of pages". HTH Robert bobrics wrote: > Hi, > > I am intersted in having two different page orientations (portrait and > landscape) on the same WORD file - landscape for longe...

Portrait Page as title for landscape document
I typed a simple report in LaTeX using landscape option of geometry package. The entire report turns out just the way I want it to, but I need to create a title page for it. Is it possible to set its orientation (back) to portrait? ...

PDF:Writer pages landscape and portrait
Hi, Im creating a PDF report and throughout the PDF document there will be some pages that need to be landscape and some that need to portrait. I cant seem to find any documentation about inserting pages in the document with a different layout, it looks like the whole document needs to be on or the other when initialising pdf = PDF::Writer.new(:orientation => :landscape) I currently have the seperate parts of the document rendering individually so one option would be to merge them altogether when finished and use the page numbering to tie them together. Can anyone give some advice on th...

rotating to portrait when printing landscape pdf
I want to transform pdf in landscape into Fax TIFF format, rotating pages 90 degrees to fit the fax page . I'm using Ghostscript like this: gswin32c -dNOPAUSE -dBATCH -sDEVICE=tiffg3 -q -c "<< /Policies << /PageSize 5 >> /PageSize [595 842] /InputAttributes << 0 << /PageSize [595 842] >> >> >> setpagedevice" -f yourfile.pdf -sOutputFile=%2 %1 The command is not working with Ghostscript 8.53 With Ghostscript 8.00 everything worked fine. Another fax devices: faxg3, faxg32d and faxg4 are not working at all (Unknown device error). ...