|
-
Mar 27th, 2009, 02:43 PM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Increase Height of Printed Text
I'm in the process of making a barcode printing program for my job.
The barcode is printed by printing text using font "WASP 39 LC". I have it automatically determining the correct font size of the text so that it will stretch from the left edge to the right edge, but the barcode isn't very wide (or tall), It's only about a centimeter tall (when printing a 9-digit number).
I'd like to increase the height of the text without increasing the width also.
Does anyone have any ideas about how I could accomplish this? I thought maybe printing the text to a picturebox, increasing the height of that, and painting it on the barcode, but I can't seem to figure out how to do that.
Any input is immensely appreciated!
Code:
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.PageSettings.PaperSize.Height = 250 'Height(inch) * 100
e.PageSettings.PaperSize.Width = 400 'Width(inch) * 100
sAcctCode = txtAcctCode.Text
sAcctName = txtAcctName.Text
sValue = "*" & txtBarcode.Text & "*"
Dim f As Font
Dim p As Point
Dim siz As Integer
f = New Font("Times New Roman", 20, FontStyle.Regular)
p.X = (e.PageSettings.PaperSize.Width / 2) - (e.Graphics.MeasureString("FILEFOLDERS ONLY", f).Width / 2)
p.Y = e.PageSettings.PaperSize.Height - e.Graphics.MeasureString("(FILEFOLDERS ONLY)", f).Height
e.Graphics.DrawString("(FILEFOLDERS ONLY)", f, Brushes.Black, p)
siz = 1
f = New Font("WASP 39 LC", siz, FontStyle.Regular)
Do Until e.Graphics.MeasureString(sValue, f).Width >= e.PageSettings.PaperSize.Width
siz = siz + 1
f = New Font("WASP 39 LC", siz, FontStyle.Regular)
Loop
siz = siz - 3
p.X = (e.PageSettings.PaperSize.Width / 2) - (e.Graphics.MeasureString(sValue, f).Width / 2)
p.Y = p.Y - (e.Graphics.MeasureString(sValue, f).Height) - 20
e.Graphics.DrawString(sValue, f, Brushes.Black, p)
siz = 12
f = New Font("Times New Roman", siz, FontStyle.Bold)
If e.Graphics.MeasureString(sAcctName, f).Width > e.PageSettings.PaperSize.Width Then
Do Until e.Graphics.MeasureString(sAcctName, f).Width < e.PageSettings.PaperSize.Width
siz = siz - 1
f = New Font("Times New Roman", siz, FontStyle.Bold)
Loop
End If
Dim pic As New PictureBox 'Draw barcode & Increase height
siz = siz - 3
p.Y = p.Y - e.Graphics.MeasureString(sAcctName, f).Height
p.X = p.X + 5
e.Graphics.DrawString(sAcctName, f, Brushes.Black, p)
siz = 12
f = New Font("Times New Roman", siz, FontStyle.Bold)
If e.Graphics.MeasureString(sAcctCode, f).Width > e.PageSettings.PaperSize.Width Then
Do Until e.Graphics.MeasureString(sAcctCode, f).Width < e.PageSettings.PaperSize.Width
siz = siz - 1
f = New Font("Times New Roman", siz, FontStyle.Bold)
Loop
End If
siz = siz - 3
p.Y = p.Y - e.Graphics.MeasureString(sAcctCode, f).Height
e.Graphics.DrawString(sAcctCode, f, Brushes.Black, p)
siz = 14
f = New Font("Times New Roman", siz, FontStyle.Bold)
p.Y = 10
p.X = 5
e.Graphics.DrawString("Retrievex", f, Brushes.Black, p)
p.X = e.PageSettings.PaperSize.Width - e.Graphics.MeasureString("888-869-2767", f).Width - 10
e.Graphics.DrawString("888-869-2767", f, Brushes.Black, p)
End Sub
-
Mar 27th, 2009, 09:41 PM
#2
Re: Increase Height of Printed Text
To implement your suggestion you can create a Bitmap object of the appropriate size and then call Graphics.FromImage to create a Graphics object. You can then call DrawString on that Graphics object to draw your barcode onto the Bitmap. Make sure you then Dispose the Graphics object, which is best done by creating it with a Using statement. You can then print your Bitmap by calling DrawImage, which will allow you to stretch it by specifying an area larger than the Bitmap itself.
Alternatively, you should be able to call the ScaleTransform method of the Graphics object already provided by the PrintPage event handler. If you pass 1.0F as the first argument then everything will stay the same width as norma. You can then pass a multipler for the height as the second argument, e.g. if you pass 2.0F then everything will be twice as tall. Just note that, if you do it this way, the vertical position will be doubled as well as the vertical size, so you'll need to adjust all your Y values accordingly.
Also, note that, if you try this second option, you should call ResetTransform when you're done.
-
Mar 28th, 2009, 04:55 PM
#3
Thread Starter
Hyperactive Member
Re: Increase Height of Printed Text
sounds perfect!! i'll play with it on monday.
Thanks!!
-
Mar 30th, 2009, 08:26 AM
#4
Thread Starter
Hyperactive Member
Re: Increase Height of Printed Text
The Graphics.ScaleTransform worked great!!!
Thanks so much!! You rock!!
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
|