I want to print vertical text on the printer. What's the API call I need?
Attachment 107695
Printable View
I want to print vertical text on the printer. What's the API call I need?
Attachment 107695
I did it with code like this
All stuff I found online if you want to google around for those method names and such...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
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 ;)
Stranger things have happened.
>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.
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...
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.
By the way, the second link proposes 2 methods. The first of these two uses this code (API definitions not included here):
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: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
Printer.Print
at the very beginning.
Does that make any sense?
Code you possibly post the code you are using? There might be something interfering with the way the code is suppose to function.