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. Dim doc = New GcPdfDocument()
  17. Dim page As Page = Nothing
  18. Dim g As GcGraphics = Nothing
  19. Const margin = 72.0F / 2
  20. Const pad = 4.0F
  21. Const gap = 10.0F
  22. Dim ip = New PointF(margin, margin)
  23.  
  24. Dim newPage As Action =
  25. Sub()
  26. page = doc.NewPage()
  27. g = page.Graphics
  28. ip = New PointF(margin, margin)
  29. End Sub
  30.  
  31. newPage()
  32.  
  33. Dim tfCaption = New TextFormat() With {
  34. .Font = StandardFonts.Times,
  35. .FontSize = 12
  36. }
  37. Dim tfBarcode = New TextFormat() With {
  38. .Font = StandardFonts.Helvetica,
  39. .FontSize = 9
  40. }
  41. Dim barcode = New GcBarcode() With {
  42. .TextFormat = tfBarcode,
  43. .ScaleFactor = 1.5F
  44. }
  45. barcode.Options.CaptionPosition = BarCodeCaptionPosition.Below
  46. barcode.Options.SizeOptions.NarrowWideRatio = 0
  47.  
  48. Dim drawBarcode As Action(Of CodeType, String, String) =
  49. Sub(ct_, txt_, txt2_)
  50. Dim caption = $"{ct_}:{vbCrLf}{txt_}"
  51. If String.IsNullOrEmpty(txt2_) Then
  52. barcode.Options.GS1Composite.Type = GS1CompositeType.None
  53. Else
  54. caption += $"{vbCrLf}Dependent CCA: {txt2_}"
  55. barcode.Options.GS1Composite.Type = GS1CompositeType.CCA
  56. barcode.Options.GS1Composite.Value = txt2_
  57. End If
  58.  
  59. barcode.Options.CheckSumEnabled = ct_ <> CodeType.Code25intlv AndAlso ct_ <> CodeType.Code_2_of_5 AndAlso ct_ <> CodeType.Matrix_2_of_5
  60. Dim csize = g.MeasureString(caption, tfCaption)
  61. barcode.CodeType = ct_
  62. barcode.Text = txt_
  63. Dim size = g.MeasureBarcode(barcode)
  64. size.Height = Math.Max(size.Height, csize.Height)
  65. Dim border = New RectangleF(ip, New SizeF(page.Size.Width - margin * 2, size.Height + pad * 2))
  66. If ip.Y + border.Height > page.Size.Height - margin Then
  67. newPage()
  68. border = New RectangleF(ip, border.Size)
  69. End If
  70. g.DrawRectangle(border, Color.Gray)
  71. g.DrawString(caption, tfCaption, New PointF(border.Left + pad, border.Top + pad))
  72. g.DrawBarcode(barcode, New RectangleF(border.Right - size.Width - pad, border.Top + pad, size.Width, size.Height))
  73. ip.Y = border.Bottom + gap
  74. End Sub
  75. ''
  76. drawBarcode(CodeType.Ansi39, "*DSBARCODE*", Nothing)
  77. drawBarcode(CodeType.Ansi39x, "*DsPdf*", Nothing)
  78. drawBarcode(CodeType.Codabar, "A12041961D", Nothing)
  79. drawBarcode(CodeType.Code25intlv, "1234567890", Nothing) '' Interleaved 2 of 5 (ITF)
  80. drawBarcode(CodeType.Code39, "*GCBARCODE*", Nothing)
  81. drawBarcode(CodeType.Code39x, "*DsPdf*", Nothing)
  82. drawBarcode(CodeType.Code49, "DsBarcode+DsPdf", Nothing)
  83. drawBarcode(CodeType.Code93x, "DsBarcode+DsPdf", Nothing)
  84. drawBarcode(CodeType.Code_93, "GCBARCODE", Nothing)
  85. drawBarcode(CodeType.Code_128_A, "DSPDF-2023", Nothing)
  86. drawBarcode(CodeType.Code_128_B, "DSPdf-2023", Nothing)
  87. drawBarcode(CodeType.Code_128_C, "1234567890", Nothing)
  88. drawBarcode(CodeType.Code_128auto, "DsPdf-2023", Nothing)
  89. drawBarcode(CodeType.Code_2_of_5, "1234567890", Nothing)
  90. drawBarcode(CodeType.DataMatrix, "DsBarcode+DsPdf", Nothing)
  91. drawBarcode(CodeType.QRCode, "DsBarcode+DsPdf", Nothing)
  92. drawBarcode(CodeType.EAN_8, "1234567", Nothing)
  93. drawBarcode(CodeType.EAN_13, "469" + "87654" + "3210", Nothing)
  94. drawBarcode(CodeType.EAN128FNC1, $"GcBarcode{vbLf}DsPdf", Nothing)
  95. drawBarcode(CodeType.IntelligentMail, "00300999999000000001", Nothing)
  96. drawBarcode(CodeType.JapanesePostal, "TOKYO-10CC-09-1978", Nothing)
  97. drawBarcode(CodeType.PostNet, "152063949", Nothing)
  98. drawBarcode(CodeType.RM4SCC, "SE17PB9Z", Nothing)
  99. drawBarcode(CodeType.Matrix_2_of_5, "1234567890", Nothing)
  100. drawBarcode(CodeType.MSI, "1234567890", Nothing)
  101. drawBarcode(CodeType.MicroPDF417, "DsPdf", Nothing)
  102. drawBarcode(CodeType.Pdf417, "DsPdf", Nothing)
  103. drawBarcode(CodeType.RSS14, "1234567890", Nothing)
  104. drawBarcode(CodeType.RSS14Stacked, "1234567890", Nothing)
  105. drawBarcode(CodeType.RSS14Stacked, "1234567890", "12345")
  106. drawBarcode(CodeType.RSS14StackedOmnidirectional, "1234567890", Nothing)
  107. drawBarcode(CodeType.RSS14Truncated, "1234567890", Nothing)
  108. drawBarcode(CodeType.RSSExpanded, "12345678901234", Nothing)
  109. drawBarcode(CodeType.RSSExpandedStacked, "12345678901234", Nothing)
  110. drawBarcode(CodeType.RSSLimited, "1234567890", Nothing)
  111. drawBarcode(CodeType.RSSLimited, "1234567890", "12345")
  112. drawBarcode(CodeType.UCCEAN128, "DsBarcode+DsPdf", Nothing)
  113. drawBarcode(CodeType.UPC_A, "123456789012", Nothing)
  114. drawBarcode(CodeType.UPC_E0, "123456789012", Nothing)
  115. drawBarcode(CodeType.UPC_E1, "123456789012", Nothing)
  116. ''
  117. '' Done:
  118. doc.Save(stream)
  119. Return doc.Pages.Count
  120. End Function
  121. End Class
  122.