Click here to Skip to main content
15,867,568 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
So, I've wrote a program awhile ago that prints barcode labels. The old version needed the font to be installed in the fonts folder, but that made it a pain for people using the program for the first time, as the program would print the barcode label with a default font. If I load the font file directly and try and print, it just shows up with the default font, obviously not a barcode. The following doesn't seem to work:
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)

        Dim pointF As New PointF(0, 0)

        Dim drawFormat As New StringFormat
        drawFormat.FormatFlags = StringFormatFlags.DirectionVertical

        Dim drawBrush As New SolidBrush(Color.Black)

        ' Install and size the font
        Dim barcodeFont As Font
        Dim barcodeFontSize = 36
        Dim pfc As New PrivateFontCollection
        pfc.AddFontFile("FRE3OF9X.TTF")
        barcodeFont = New Font(pfc.Families(0), barcodeFontSize)
        e.Graphics.DrawString(serial, barcodeFont, drawBrush, pointF, drawFormat)

        ' There are no more pages.
        e.HasMorePages = False
    End Sub


This is the old way, and it does work:
Private Sub Print_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs)

        Dim pointF As New PointF(0, 0)

        Dim drawFormat As New StringFormat
        drawFormat.FormatFlags = StringFormatFlags.DirectionVertical

        Dim drawBrush As New SolidBrush(Color.Black)

        ' Install and size the font
        Dim barcodeFont As Font
        Dim barcodeFontSize = 36
        barcodeFont = New Font("Free 3 of 9 Extended", barcodeFontSize)
        e.Graphics.DrawString(serial, barcodeFont, drawBrush, pointF, drawFormat)

        ' There are no more pages.
        e.HasMorePages = False
    End Sub


I'd really like to have it where I don't have to install the font on the system, so if anyone has any insight, I'd greatly appreciate it.

~Brandon
Posted

1 solution

I guess "FRE3OF9X.TTF" isn't a valid font family. Look at the msdn example below.

http://msdn.microsoft.com/en-us/library/y505zzfw.aspx[^]

Good luck!
 
Share this answer
 
Comments
freemanirl 27-Jul-10 22:32pm    
I've loaded this font into a font family and successfully printed a barcode text onto a picture box. For some reason the same process doesn't work here. I was thinking of creating a bitmap and then printing the bitmap, but that seems very round-a-bout.
E.F. Nijboer 28-Jul-10 12:24pm    
Maybe it's simply not supported...
Look at the remark at this link:
http://msdn.microsoft.com/en-us/library/system.drawing.text.privatefontcollection.addfontfile.aspx

Also, the OS support is somewhat limited so that could be a problem as well. Although it would be kinda strange because in a project I'm involved with we use the same font on a Windows 2000 machine, although it is installed and the application is build with Delphi.

By the way, found this in the message board here on codeproject that looks promising:
http://www.codeproject.com/Messages/2446682/Re-Font-problem-in-windows-Vista-modified.aspx

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900