|
-
Nov 27th, 2013, 11:41 AM
#1
Print vertical text
I want to print vertical text on the printer. What's the API call I need?
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)
-
Nov 27th, 2013, 11:48 AM
#2
-
Nov 27th, 2013, 11:59 AM
#3
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...
-
Nov 27th, 2013, 12:11 PM
#4
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
-
Nov 27th, 2013, 12:13 PM
#5
Re: Print vertical text
 Originally Posted by DataMiser
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!!
-
Nov 27th, 2013, 01:20 PM
#6
Re: Print vertical text
Stranger things have happened.
-
Nov 27th, 2013, 03:27 PM
#7
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.
-
Nov 27th, 2013, 03:36 PM
#8
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...
-
Nov 27th, 2013, 03:53 PM
#9
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.
-
Nov 28th, 2013, 04:23 AM
#10
Re: Print vertical text
 Originally Posted by dilettante
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)
-
Nov 28th, 2013, 04:26 AM
#11
Re: Print vertical text
 Originally Posted by szlamany
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)
-
Nov 28th, 2013, 05:07 AM
#12
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)
-
Nov 28th, 2013, 05:47 AM
#13
Re: Print vertical text
 Originally Posted by krtxmrtz
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...
-
Nov 28th, 2013, 05:48 AM
#14
Re: Print vertical text
 Originally Posted by krtxmrtz
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.
-
Nov 28th, 2013, 06:10 AM
#15
Re: Print vertical text
 Originally Posted by szlamany
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)
-
Nov 28th, 2013, 06:12 AM
#16
Re: Print vertical text
 Originally Posted by Me
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)
-
Nov 30th, 2013, 08:12 AM
#17
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|