Print font not available after assigning PrinterName

T

Tony Girgenti

Hello.

Developing a Windows Form program in VS.NET VB, .NET Framework 1.1.4322 on a
windows XP Pro, SP2.

Before printing a document, i want to set the font to a font that is only
available with the printer that i am printing to(Zebra TLP2844).

When i open Word and look at the fonts available for the default printer, it
does not show the fonts i want. If i cahnge the printer to the printer that
has the font that i want, the font i want shows up in the font selections.
This seems to be true for any program that allows me to select a font for
printing (Excel, Notepad, etc.)

In my VB program i set the PrinterSettings.PrinterName property to the name
of the printer that has the fonts that i want to print with. After that i
set the print font to the font i want, which is associated with the printer
in PrinterSettings.PrinterName.

When i go to print, it does not use the font that i am expecting. It uses
the "Microsoft Sans Serif" font.

I have taken it through the debugger and i can see that it is picking up the
right printer from PrinterSettings.InstalledPrinters. I can change to other
fonts that are installed for the default printer and it prints in those
fonts. I just can't change to a font for the Zebra printer even though i
set the PrinterSettings.PrinterName to the Zebra printer.

How do i change to the font that is only associated with the printer that i
am trying to use ?

Any help would be gratefully appreciated.

Thanks,
Tony
 
T

Tony Girgenti

Hello vbnetdev.

As requested, here is the code that i use:

Dim labelPrintDocument As New PrintDocument
labelPrintDocument = Me.barcodeLabelPrintDocument

labelPrintDocument.PrinterSettings.PrinterName =
PrinterSettings.InstalledPrinters.Item(0).ToString

If labelPrintDocument.PrinterSettings.IsValid Then
Dim y As String
y = labelPrintDocument.DocumentName
End If

drawingPrintFont = New Font("Arial Black", 12)
barcodePrintFont = New Font("Code 39 Std and Extended", 24)
underLinePrintFont = New Font("Arial Black", 10,
System.Drawing.FontStyle.Underline)
labelPrintDocument.DefaultPageSettings.Landscape = True

Dim labelDialog As New PrintPreviewDialog
labelDialog.Document = labelPrintDocument
labelDialog.ShowDialog()

Thanks,
Tony
 
V

vbnetdev

You might also try another approach, that is to automate your report from
Excel. In my experience I can make things work while automating under Excel
object that I can't necessarily do straight from vb.net. If you need
assistance with this contact me off list. My email here is valid.
 
T

Tony Girgenti

Hello vbnetdev.

Happy Holidays.

I don't think this is true. Is "3 of 9 Barcode" a truetype font? I tried
using that font in VB.NET and it worked.

Thanks,
Tony
 
T

Tony Girgenti

Hello vbnetdev.

Happy Holidays.

I'm trying to use the VB example at this link. It gives me an error on the
last line of the example "e.Graphics.DrawString(familyList, font,
solidBrush, rectF)" If i put the example code in a button_click sub, it
says that "Graphics is not a member of System.EventArgs".

If i replace the "ByVal e As System.EventArgs" with "ByVal e As
System.Windows.Forms.PaintEventArgs", it gets rid of that error but then
says "Method 'Button1_Click' cannot handle Event 'Click" because they do not
have the same signature" on the SUB line.

I'm not sure of how to code this to do a test. I'd like to see the results
it would produce.

Thanks,
Tony
 
V

vbnetdev

Copy and paste this code in a new form...

Private pictureBox1 As New PictureBox()

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
pictureBox1.Dock = DockStyle.Fill
pictureBox1.BackColor = Color.White
AddHandler pictureBox1.Paint, AddressOf Me.pictureBox1_Paint
Me.Controls.Add(pictureBox1)
End Sub
Private Sub pictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs)
' Create a local version of the graphics object for the PictureBox.
Dim fontFamily As New FontFamily("Arial")
Dim font As New Font( _
fontFamily, _
8, _
FontStyle.Regular, _
GraphicsUnit.Point)
Dim rectF As New RectangleF(10, 10, 500, 500)
Dim solidBrush As New SolidBrush(Color.Black)

Dim familyName As String
Dim familyList As String = ""
Dim fontFamilies() As FontFamily

Dim installedFontCollection As New
Drawing.Text.InstalledFontCollection()

fontFamilies = installedFontCollection.Families

Dim count As Integer = fontFamilies.Length
Dim j As Integer

While j < count
familyName = fontFamilies(j).Name
familyList = familyList & familyName
familyList = familyList & ", "
j += 1
End While

e.Graphics.DrawString(familyList, font, solidBrush, rectF)
Dim g As Graphics = e.Graphics

g.DrawString(familyList, font, solidBrush, rectF)
End Sub 'pictureBox1_Paint

Public Delegate Sub PaintEventHandler( _
ByVal e As PaintEventArgs _
)
 
T

Tony Girgenti

Hello vbnetdev.

OK. That showed all the fonts. However it does not show the one that i am
looking for. It does not show the fonts that appear for a document when i
select the Zebra printer in Word.

Thanks,
Tony
 
V

vbnetdev

Now in MS Word....

Basically record a macro, selecting this font. Take a look at that code. You
will need that to automate the report. Now as long as this printer is your
default printer you should have no trouble automating this report in vb.net.

If you need help automating this report, this is one of my specialities and
will be happy to consult with you on this off list.
 
T

Tony Girgenti

Hello vbnetdev.

I guess i should have explained that this is not really a report, it's a
barcode label. We are trying to get away from Word and right now they are
printing their labels from Word.

Happy New Year !

Thanks,
Tony
 
V

vbnetdev

ahhhh this is more sense to me now.

Let me look into this a little more. Why do they want to stop using Word?
Too slow?
 
T

Tony Girgenti

The Word template is just too easy to mess up. We are using fields to
accept the barcode number and other items and then they select file/print
from the menu.

Sometimes they save the template with the label data init and they
shouldn't, they lose it from the desktop, the default printer gets reset by
somebody using the computer and then the person printing barcode labels does
not know how to select the label printer, etc.

Using a VB program is an all around cleaner way to allow the user to do the
things that they need to do which includes other tasks besides printing
barcode labels.

Thanks,
Tony
 
V

vbnetdev

what would you say if we could devise a program that would talk to the
template, do what needs to be done and they never see it? all they do is
actually enter the data in the program that accesses the template?
 
T

Tony Girgenti

I would say "Thanks alot".

Thanks,
Tony

vbnetdev said:
what would you say if we could devise a program that would talk to the
template, do what needs to be done and they never see it? all they do is
actually enter the data in the program that accesses the template?
 
R

RobinS

You should go over to your local Barnes & Noble and check out
Tim Patrick's book, "Start-to-Finish VB2005". I haven't finished
it yet (it's a great book for learning VB2005), but it does have
bar code design and printing stuff in it.

Robin S.
------------------------------------
 
T

Tony Girgenti

Hello Robin.

Good Idea. I will check that out even though i am using VS2003.

Thanks,
Tony
 
V

vbnetdev

well Tony send me a template, what you are sending for data. If you have the
project zip it up and send it and let me see what I can do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top