[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 241
  • Last Modified:

Rotate Text to Printer?

Hi!

I want to print a text to a printer, with 90°. Does somebody know, how i can do this?

Thanks in advanced

Pierre
0
Falk2
Asked:
Falk2
  • 3
  • 2
  • 2
  • +2
1 Solution
 
Erick37Commented:
"Printing Rotated Text with Visual Basic"
http://support.microsoft.com/support/kb/articles/Q175/5/35.ASP
0
 
mbah022100System enigineerCommented:
I use this code to print by 90°:

Private Const FW_DONTCARE = 0
Private Const FW_THIN = 100
Private Const FW_EXTRALIGHT = 200
Private Const FW_ULTRALIGHT = 200
Private Const FW_LIGHT = 300
Private Const FW_NORMAL = 400
Private Const FW_REGULAR = 400
Private Const FW_MEDIUM = 500
Private Const FW_SEMIBOLD = 600
Private Const FW_DEMIBOLD = 600
Private Const FW_BOLD = 700
Private Const FW_EXTRABOLD = 800
Private Const FW_ULTRABOLD = 800
Private Const FW_HEAVY = 900
Private Const FW_BLACK = 900

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 Type SIZE
  cx As Long
  cy As Long
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 GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As SIZE) 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 ' or Boolean
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
                               
Public Sub pPrint(sText As String, lHeight As Long)
  Dim log_font As LOGFONT
  Dim log_size As SIZE
  Dim new_font As Long
  Dim old_font As Long
  Dim lRc As Long
 
  ' Create the rotated font.
  pCreatePrinterFont log_font, 90, 10 , "Arial"
  new_font = CreateFontIndirect(log_font)

  ' Select the font.
  old_font = SelectObject(Printer.hdc, new_font)

  ' Draw the text.
  lRc = GetTextExtentPoint32(Printer.hdc, sText, Len(sText), log_size)
 
  lRc = TextOut(Printer.hdc, your Y position, your X position, sText, Len(sText))
 
  ' Restore the original font.
  SelectObject hdc, old_font
  DeleteObject new_font

End Sub

Private Sub pCreatePrinterFont(log_fnt As LOGFONT, iAngle As Integer, fFontSize as Single, sFontName as String)
  With log_fnt
    .lfEscapement = iAngle * 10
    If m_bFontBold = True Then
      .lfWeight = FW_BOLD
    End If
    .lfItalic = False
    .lfUnderline = False
    .lfStrikeOut = False
    .lfHeight = (fFontSize * -(Printer.TwipsPerPixelX * 8.33)) / Printer.TwipsPerPixelX
    .lfFaceName = sFontName & vbNullChar
  End With
End Sub

If you check this code carfully you can see that it is possible to print by any angle.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
Falk2Author Commented:
AzraSound's answer was the first and best one, but i can't give him the points...
0
 
AzraSoundCommented:
because?
0
 
AzraSoundCommented:
submitting comment as answer
0
 
Falk2Author Commented:
It works fantastics

Only no word has been said about Printer-Resolution and it's relationship with the x and y coordinate.
0
 
darinwCommented:
Falk2: If the answer was 'fantastic', why did you assign a B grade?

Just curious. There is no way to undo a grade once it is done though, but I am sure the Expert would like to know as well.

darinw
Customer Service
0
 
darinwCommented:
>Only no word has been said about Printer-Resolution and it's relationship
with the x and y coordinate.

If I am not mistaken, that was not the question.

darinw
Customer Service
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now