Results 1 to 17 of 17

Thread: Print vertical text

  1. #1

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Print vertical text

    I want to print vertical text on the printer. What's the API call I need?
    Name:  vt.png
Views: 1531
Size:  3.1 KB
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  2. #2

  3. #3
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Print vertical text

    I did it with code like this

    Code:
                                f.picRotate.Cls
                                f.picRotate.BackColor = vbWhite
                                
                                VertFont.lfEscapement = 2700    ' 180-degree rotation
                                VertFont.lfFaceName = objprt.Font & Chr$(0) 'Null character at end
                                ' Windows expects the font size to be in pixels and to be negative if you are specifying the character height you want.
                                VertFont.lfHeight = (objprt.FontSize * -20) / Screen.TwipsPerPixelY
                                VertFont.lfWeight = 700
                                lnghFont = CreateFontIndirect(VertFont)
                                lngPrevFont = SelectObject(f.picRotate.hdc, lnghFont)
    
                                s3 = strRS(prtItems(i, 3), lngRS)
                                f.picRotate.CurrentX = objprt.FontSize * 20 * 1.2
                                f.picRotate.CurrentY = 0
                                f.picRotate.Width = prtItems(i, 5)
                                f.picRotate.Height = prtItems(i, 6)
                                f.picRotate.Print s3;
    
                                objprt.PaintPicture f.picRotate.Image, lngOffsetX + prtItems(i, 2), prtItems(i, 4) ', f.picRotate.TextHeight(s3), f.picRotate.TextWidth(s3)
    
                                lngRet = SelectObject(f.picRotate.hdc, lngPrevFont)
                                lngRet = DeleteObject(lnghFont)
    
                                objprt.CurrentX = lngHoldX
                                objprt.CurrentY = lngHoldY
    All stuff I found online if you want to google around for those method names and such...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  4. #4
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,206

    Re: Print vertical text

    Umm are we talking some text one way and some text the other? Because if you just want the text rotated like that you can simply change the printer to landscape mode and print normally

  5. #5
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Print vertical text

    Quote Originally Posted by DataMiser View Post
    Umm are we talking some text one way and some text the other? Because if you just want the text rotated like that you can simply change the printer to landscape mode and print normally
    Wouldn't that be funny if that was the real question!!

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  6. #6
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Print vertical text

    Stranger things have happened.

  7. #7
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: Print vertical text

    >objprt.PaintPicture f.picRotate.Image, lngOffsetX + prtItems(i, 2), prtItems(i, 4)
    A novel approach but I think it probably results in an image at (low)screen resolution being 'pasted' on to one at (higher)printer resolution. To print the text at best quality it should be printed directly to the printer as per the 2nd examples linked to previously by dil.

  8. #8
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Print vertical text

    It was for a PURCHASE ORDER # to appear along the "right side" of the document - the "resolution" of it was kind of secondary - actually looked ok with it being choppier...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  9. #9
    Frenzied Member
    Join Date
    Mar 2008
    Posts
    1,210

    Re: Print vertical text

    The result/ size of the pasted image may also be affected by the users current screen dpi setting so it could be 'choppy' at 96dpi, better and or a different size at 120dpi etc.

  10. #10

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Print vertical text

    The code from the second link seems to be exactly what I need, thanks.

    And, I am printing horizontal text as well, Landscape orientation is out of the question
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  11. #11

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Print vertical text

    Quote Originally Posted by szlamany View Post
    I did it with code like this...
    I assume objprt may be a variable representing the printer, a picturebox, etc. But what kind of object is f?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  12. #12

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Print vertical text

    By the way, the second link proposes 2 methods. The first of these two uses this code (API definitions not included here):
    Code:
       Private Sub Command1_Click()
       ' Combine API Calls with the Printer object
          Dim OutString As String
          Dim lf As LOGFONT
          Dim result As Long
          Dim hOldfont As Long
          Dim hPrintDc As Long
          Dim hFont As Long
    
          'Printer.Print "Printer Object"
          hPrintDc = Printer.hdc
          OutString = "Hello World"
    
          lf.lfEscapement = 1800
          lf.lfHeight = (DESIREDFONTSIZE * -20) / Printer.TwipsPerPixelY
          hFont = CreateFontIndirect(lf)
          hOldfont = SelectObject(hPrintDc, hFont)
          result = TextOut(hPrintDc, 1000, 1000, OutString, Len(OutString))
          result = SelectObject(hPrintDc, hOldfont)
          result = DeleteObject(hFont)
    
          'Printer.Print "xyz"
          Printer.EndDoc
       End Sub
    where I have commented out 2 "normal" Printer.Print statements. But precisely in this case the printer doesn't print anything. The only way to have it print my rotated text and nothing else is by using a Print statement, for example:

    Printer.Print

    at the very beginning.

    Does that make any sense?
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  13. #13
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Print vertical text

    Quote Originally Posted by krtxmrtz View Post
    I assume objprt may be a variable representing the printer, a picturebox, etc. But what kind of object is f?
    objprt can be a printer or a picture box - it's both in that app - so I can see my reports on screen as well...

    "f" is a form reference...

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  14. #14
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: Print vertical text

    Quote Originally Posted by krtxmrtz View Post
    Printer.Print

    at the very beginning.

    Does that make any sense?
    Maybe the currentX and currentY needs to "grow" past the area that you are vertical printing in. Instead of the two .PRINT's - try setting the .CurrentX and .CurrentY values.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

  15. #15

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Print vertical text

    Quote Originally Posted by szlamany View Post
    Maybe the currentX and currentY needs to "grow" past the area that you are vertical printing in. Instead of the two .PRINT's - try setting the .CurrentX and .CurrentY values.
    I'd already tried to no avail.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  16. #16

    Thread Starter
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: Print vertical text

    Quote Originally Posted by Me View Post
    The code from the second link seems to be exactly what I need...
    Now this is funny: the example works but then, when I transcribe the code to my own project it just ignores the lf.lfEscapement value and the text is not rotated!
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  17. #17
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: Print vertical text

    Code you possibly post the code you are using? There might be something interfering with the way the code is suppose to function.
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width