I have an ASP.Net program which shows crystal report but the problem is showing if barcode. The barcode won't show unless the font is installed on the client's PC. Is there a way to show the barcode without installing it?
What I have tried:
I've tried passing byte into datatable with column byte. But something seems wrong or missing;
Sub GenerateReport
Dim dt As New DataTable()
dt.Columns.Add("colBarcode", GetType(Byte()))
Dim dr As DataRow = dt.NewRow()
dr("colBarcode") = code.Token(cntnum)
dt.Rows.Add(dr)
reportDocument.Database.Tables(0).SetDataSource(dt)
End Sub
Public Function Tokhgen(ByVal a As String) As Byte()
Dim text As String = "*" + a + "*"
Dim bitmap As New Bitmap(1, 1)
'Adding font as private font
Try
Dim fontName As String = "IDAutomationHC39M Free Version.otf"
Dim pfcoll As New PrivateFontCollection()
'put a font file under a Fonts directory within your application root
pfcoll.AddFontFile(System.Web.Hosting.HostingEnvironment.MapPath(Convert.ToString("~/style/") & fontName))
Dim myFontFamily As FontFamily = pfcoll.Families(0)
' Dim myFontFamily As New FontFamily("IDAutomationHC39M Free Version")
Dim font As New Font(myFontFamily, 200, FontStyle.Regular, GraphicsUnit.Pixel)
Dim graphics__1 As Graphics = Graphics.FromImage(bitmap)
Dim width As Integer = CInt(graphics__1.MeasureString(text, font).Width)
Dim height As Integer = CInt(graphics__1.MeasureString(text, font).Height)
bitmap = New Bitmap(bitmap, New Size(width, height))
graphics__1 = Graphics.FromImage(bitmap)
graphics__1.Clear(Color.White)
graphics__1.SmoothingMode = SmoothingMode.AntiAlias
graphics__1.TextRenderingHint = TextRenderingHint.AntiAlias
graphics__1.DrawString(text, font, New SolidBrush(Color.FromArgb(0, 0, 0)), 0, 0)
graphics__1.Flush()
graphics__1.Dispose()
Dim ms As New MemoryStream()
bitmap.Save(ms, ImageFormat.Jpeg)
Dim base64Data = Convert.ToBase64String(ms.ToArray())
Return ms.ToArray()
Catch ex As Exception
End Try
End Function