Print preview does not display barcode

When I write directly to the Windows Form it looks fine, when I print to the printer from the preview it looks fine. However, the print preview itself does not output the barcode text in 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?

0


a source to share


1 answer


The printer either had fonts, or my printing method made graphics from them on the way to the printers I was trying to print to. Once I installed these fonts on the computer I was on, Printpreview worked as well.



+1


a source







All Articles