M
MarcoGG
Guest
Hi,
I'm trying to get into a simple task, but something goes wrong.
I want my VB 2015 Application to use some True Type Fonts available in a local path as .ttf files.
Please NOTE that my desired Fonts are NOT installed on test pc, and I don't want end user to be forced to install them.
So these "custom fonts" must be used on Form Controls and also printed correctly on paper ( PrintDocument object ).
Here's a simple example of the code I'm using.
1. Declarations :
Private mFont As Font
Private WithEvents mPD As New Printing.PrintDocument
2. Job :
Dim pathCustomFonts As String = Application.StartupPath & "\FONTS\"
Dim PFC As New System.Drawing.Text.PrivateFontCollection
PFC.AddFontFile(pathCustomFonts & "MyTrueTypeFont.ttf")
mFont = New Font(PFC.Families(0), 32, FontStyle.Regular)
'View on Form Control
txt_test.Text = "Aa Bb Cc 1234567890"
txt_test.Font = mFont
'View on PrintDocument
mPD.DefaultPageSettings.PaperSize = New Printing.PaperSize("Custom", 600, 400)
'Tried also with "Microsoft Print to PDF", and others ...
mPD.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"
Dim PPD As New PrintPreviewDialog
PPD.Document = mPD
PPD.ShowDialog()
3. PrintPage event :
Private Sub mPD_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mPD.PrintPage
e.Graphics.DrawString("Aa Bc Cc 1234567890",
mFont,
Brushes.Black,
New Point(50, 50))
End Sub
The problem is that I can use any True-Type Font in my Application even if not installed on test pc,
BUT Print Preview ( and actual Print job ) shows always the same default Font ( seems Arial or Sans-Serif ).
How to make custom fonts really available for PrintDocument object ?
Thanks to anyone able to help.
Continue reading...
I'm trying to get into a simple task, but something goes wrong.
I want my VB 2015 Application to use some True Type Fonts available in a local path as .ttf files.
Please NOTE that my desired Fonts are NOT installed on test pc, and I don't want end user to be forced to install them.
So these "custom fonts" must be used on Form Controls and also printed correctly on paper ( PrintDocument object ).
Here's a simple example of the code I'm using.
1. Declarations :
Private mFont As Font
Private WithEvents mPD As New Printing.PrintDocument
2. Job :
Dim pathCustomFonts As String = Application.StartupPath & "\FONTS\"
Dim PFC As New System.Drawing.Text.PrivateFontCollection
PFC.AddFontFile(pathCustomFonts & "MyTrueTypeFont.ttf")
mFont = New Font(PFC.Families(0), 32, FontStyle.Regular)
'View on Form Control
txt_test.Text = "Aa Bb Cc 1234567890"
txt_test.Font = mFont
'View on PrintDocument
mPD.DefaultPageSettings.PaperSize = New Printing.PaperSize("Custom", 600, 400)
'Tried also with "Microsoft Print to PDF", and others ...
mPD.PrinterSettings.PrinterName = "Microsoft XPS Document Writer"
Dim PPD As New PrintPreviewDialog
PPD.Document = mPD
PPD.ShowDialog()
3. PrintPage event :
Private Sub mPD_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles mPD.PrintPage
e.Graphics.DrawString("Aa Bc Cc 1234567890",
mFont,
Brushes.Black,
New Point(50, 50))
End Sub
The problem is that I can use any True-Type Font in my Application even if not installed on test pc,
BUT Print Preview ( and actual Print job ) shows always the same default Font ( seems Arial or Sans-Serif ).
How to make custom fonts really available for PrintDocument object ?
Thanks to anyone able to help.
Continue reading...