tags:

views:

277

answers:

1

When I write to the windows form directly it looks fine, when I print to the printer from the print preview it looks fine. However the print preview itself is not rendering the barcode text with the barcode font.

Public Class frmPrintPreview
Private Const testString1 As String = "*A1C1S1B1*"
Private Const testString2 As String = "*A99C99S7B3*"
Dim _BarcodeFont As System.Drawing.Text.PrivateFontCollection
Dim _BarcodeFont1 As Font
Dim _BarcodeFont2 As Font
Private Sub frmPrintPreview_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    _BarcodeFont = New System.Drawing.Text.PrivateFontCollection()
    _BarcodeFont.AddFontFile("FRE3OF9X.TTF")
    _BarcodeFont.AddFontFile("FREE3OF9.TTF")
    _BarcodeFont1 = New Font(Me._BarcodeFont.Families(0), 20, FontStyle.Regular, GraphicsUnit.Point)
    _BarcodeFont2 = New Font(Me._BarcodeFont.Families(1), 20, FontStyle.Regular, GraphicsUnit.Point)
End Sub



Private Sub PrintData(ByVal sender As Object, ByVal e As Printing.PrintPageEventArgs)
    DrawingRoutine(e.Graphics)
End Sub

Private Sub DrawingRoutine(ByRef g As Graphics)
    Dim PrintFont As Font
    PrintFont = New Font(Me.Font.FontFamily, 10.0, FontStyle.Regular) ', GraphicsUnit.Point)
    g.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
    Dim y As Int32 = 0
    g.DrawString(vbCrLf + Application.ProductName + " Version:" _
                           + Application.ProductVersion + vbCrLf _
                           + testString1, PrintFont, Brushes.Black, 0, 0)
    y += 80
    g.DrawString(testString1, Me.Font, Brushes.Black, 50, y)
    y += 40
    g.DrawString(testString1, _BarcodeFont1, Brushes.Black, 50, y)
    y += 40
    g.DrawString(testString2, Me.Font, Brushes.Black, 50, y)
    y += 40
    g.DrawString(testString2, _BarcodeFont2, Brushes.Black, 50, y)

End Sub

Private Sub btnPrint_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    DrawingRoutine(e.Graphics)
End Sub


Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
    Using printPreview As New PrintPreviewDialog()
        Dim x As New Printing.PrintDocument()
        AddHandler x.PrintPage, AddressOf PrintData
        printPreview.Document = x
        Dim result As DialogResult = printPreview.ShowDialog(Me)
        ' MsgBox(result)

    End Using
End Sub

End Class

what is wrong with my print preview?

+1  A: 

The printer either had the fonts or my printing method made graphics out of them on the way to both the printers I tried printing on. Once I installed those fonts to the computer I was on, Printpreview worked also.

Maslow