SupportedBarcodes.vb
  1. ''
  2. '' This code is part of Document Solutions for PDF demos.
  3. '' Copyright (c) MESCIUS inc. All rights reserved.
  4. ''
  5. Imports System.IO
  6. Imports System.Drawing
  7. Imports System.Collections.Generic
  8. Imports GrapeCity.Documents.Drawing
  9. Imports GrapeCity.Documents.Pdf
  10. Imports GrapeCity.Documents.Text
  11. Imports GrapeCity.Documents.Barcode
  12.  
  13. '' Renders samples of all barcode symbologies supported by the DsBarcode library.
  14. Public Class SupportedBarcodes
  15. Function CreatePDF(ByVal stream As Stream) As Integer
  16. '' Simple layout parameters:
  17. Const margin = 72.0F / 2
  18. Const pad = 4.0F
  19. Const gap = 10.0F
  20. ''
  21. Dim doc = New GcPdfDocument()
  22. Dim page As Page = Nothing
  23. Dim g As GcGraphics = Nothing
  24. Dim ip As PointF
  25. '' This will add a new page and set the insertion point initial position:
  26. Dim newPage As Action =
  27. Sub()
  28. page = doc.NewPage()
  29. g = page.Graphics
  30. ip = New PointF(margin, margin)
  31. End Sub
  32. newPage()
  33. '' Text formats for showing barcode names and values:
  34. Dim tfCaption = New TextFormat() With {
  35. .Font = StandardFonts.Times,
  36. .FontSize = 12
  37. }
  38. Dim tfBarcode = New TextFormat() With {
  39. .Font = StandardFonts.Helvetica,
  40. .FontSize = 9
  41. }
  42. '' The barcode instance to be used to draw all symbologies,
  43. '' here we set up its properties that won't change:
  44. Dim barcode = New GcBarcode() With {
  45. .TextFormat = tfBarcode,
  46. .ScaleFactor = 1.5F
  47. }
  48. barcode.Options.CaptionPosition = BarCodeCaptionPosition.Below
  49. barcode.Options.SizeOptions.NarrowWideRatio = 0
  50. '' Draw a barcode with the specified symbology (code type) and optional CC-A:
  51. Dim drawBarcode As Action(Of CodeType, String, String) =
  52. Sub(symboloty, value, cca)
  53. Dim caption = $"{symboloty}:{vbCrLf}{value}"
  54. If String.IsNullOrEmpty(cca) Then
  55. barcode.Options.GS1Composite.Type = GS1CompositeType.None
  56. Else
  57. '' Composite Component A (CC-A) specified:
  58. caption += $"{vbCrLf}Dependent CCA: {cca}"
  59. barcode.Options.GS1Composite.Type = GS1CompositeType.CCA
  60. barcode.Options.GS1Composite.Value = cca
  61. End If
  62. '' Not all barcodes support checksums:
  63. barcode.Options.CheckSumEnabled = symboloty <> CodeType.Code25intlv AndAlso symboloty <> CodeType.Code_2_of_5 AndAlso symboloty <> CodeType.Matrix_2_of_5
  64. Dim csize = g.MeasureString(caption, tfCaption)
  65. barcode.CodeType = symboloty
  66. barcode.Text = value
  67. Dim size = g.MeasureBarcode(barcode)
  68. size.Height = Math.Max(size.Height, csize.Height)
  69. Dim border = New RectangleF(ip, New SizeF(page.Size.Width - margin * 2, size.Height + pad * 2))
  70. '' Add new pages as needed:
  71. If ip.Y + border.Height > page.Size.Height - margin Then
  72. newPage()
  73. border = New RectangleF(ip, border.Size)
  74. End If
  75. '' Draw the barcode:
  76. g.DrawRectangle(border, Color.Gray)
  77. g.DrawString(caption, tfCaption, New PointF(border.Left + pad, border.Top + pad))
  78. g.DrawBarcode(barcode, New RectangleF(border.Right - size.Width - pad, border.Top + pad, size.Width, size.Height))
  79. ip.Y = border.Bottom + gap
  80. End Sub
  81. '' Draw all supported symbologies:
  82. drawBarcode(CodeType.Ansi39, "*DSBARCODE*", Nothing)
  83. drawBarcode(CodeType.Ansi39x, "*DsPdf*", Nothing)
  84. drawBarcode(CodeType.Codabar, "A12041961D", Nothing)
  85. drawBarcode(CodeType.Code25intlv, "1234567890", Nothing) '' Interleaved 2 of 5 (ITF)
  86. drawBarcode(CodeType.Code39, "*GCBARCODE*", Nothing)
  87. drawBarcode(CodeType.Code39x, "*DsPdf*", Nothing)
  88. drawBarcode(CodeType.Code49, "DsBarcode+DsPdf", Nothing)
  89. drawBarcode(CodeType.Code93x, "DsBarcode+DsPdf", Nothing)
  90. drawBarcode(CodeType.Code_93, "GCBARCODE", Nothing)
  91. drawBarcode(CodeType.Code_128_A, "DSPDF-2023", Nothing)
  92. drawBarcode(CodeType.Code_128_B, "DSPdf-2023", Nothing)
  93. drawBarcode(CodeType.Code_128_C, "1234567890", Nothing)
  94. drawBarcode(CodeType.Code_128auto, "DsPdf-2023", Nothing)
  95. drawBarcode(CodeType.Code_2_of_5, "1234567890", Nothing)
  96. drawBarcode(CodeType.DataMatrix, "DsBarcode+DsPdf", Nothing)
  97. drawBarcode(CodeType.QRCode, "DsBarcode+DsPdf", Nothing)
  98. drawBarcode(CodeType.EAN_8, "1234567", Nothing)
  99. drawBarcode(CodeType.EAN_13, "469" + "87654" + "3210", Nothing)
  100. drawBarcode(CodeType.EAN128FNC1, $"GcBarcode{vbLf}DsPdf", Nothing)
  101. drawBarcode(CodeType.IntelligentMail, "00300999999000000001", Nothing)
  102. drawBarcode(CodeType.JapanesePostal, "TOKYO-10CC-09-1978", Nothing)
  103. drawBarcode(CodeType.PostNet, "152063949", Nothing)
  104. drawBarcode(CodeType.RM4SCC, "SE17PB9Z", Nothing)
  105. drawBarcode(CodeType.Matrix_2_of_5, "1234567890", Nothing)
  106. drawBarcode(CodeType.MSI, "1234567890", Nothing)
  107. drawBarcode(CodeType.MicroPDF417, "DsPdf", Nothing)
  108. drawBarcode(CodeType.Pdf417, "DsPdf", Nothing)
  109. drawBarcode(CodeType.RSS14, "1234567890", Nothing)
  110. drawBarcode(CodeType.RSS14Stacked, "1234567890", Nothing)
  111. drawBarcode(CodeType.RSS14Stacked, "1234567890", "12345")
  112. drawBarcode(CodeType.RSS14StackedOmnidirectional, "1234567890", Nothing)
  113. drawBarcode(CodeType.RSS14Truncated, "1234567890", Nothing)
  114. drawBarcode(CodeType.RSSExpanded, "12345678901234", Nothing)
  115. drawBarcode(CodeType.RSSExpandedStacked, "12345678901234", Nothing)
  116. drawBarcode(CodeType.RSSLimited, "1234567890", Nothing)
  117. drawBarcode(CodeType.RSSLimited, "1234567890", "12345")
  118. drawBarcode(CodeType.UCCEAN128, "DsBarcode+DsPdf", Nothing)
  119. drawBarcode(CodeType.UPC_A, "123456789012", Nothing)
  120. drawBarcode(CodeType.UPC_E0, "123456789012", Nothing)
  121. drawBarcode(CodeType.UPC_E1, "123456789012", Nothing)
  122. ''
  123. '' Done:
  124. doc.Save(stream)
  125. Return doc.Pages.Count
  126. End Function
  127. End Class
  128.