Barcodes (Code 39) als PDF

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
Thorsten1867
Beiträge: 1360
Registriert: 04.02.2005 15:40
Computerausstattung: [Windows 10 x64] [PB V5.7x]
Wohnort: Kaufbeuren
Kontaktdaten:

Barcodes (Code 39) als PDF

Beitrag von Thorsten1867 »

Vielleicht kann das ja jemand gebrauchen.
Der Code benötigt PurePDF, das allerdings in PBOSL enthalten ist und somit kein Problem darstellen sollte.

Code: Alles auswählen

;/  Barcodes Code39 als PDF
;/  (basiert auf dem Code von Num3)
;/  Thorsten Hoeppner - Januar 2006

;- Benötigte PurePDF-Libary (enthalten in PBOSL)

Structure C39 
  Char.s 
  Def.s 
EndStructure 

Dim CODE39.C39 (43) 

#CharH = 5

;{ Definitionen Code39
CODE39(0)\Char = "0" : CODE39(0)\Def = "1113313111"
CODE39(1)\Char = "1" : CODE39(1)\Def = "3113111131"
CODE39(2)\Char = "2" : CODE39(2)\Def = "1133111131"
CODE39(3)\Char = "3" : CODE39(3)\Def = "3133111111"
CODE39(4)\Char = "4" : CODE39(4)\Def = "1113311131"
CODE39(5)\Char = "5" : CODE39(5)\Def = "3113311111"
CODE39(6)\Char = "6" : CODE39(6)\Def = "1133311111"
CODE39(7)\Char = "7" : CODE39(7)\Def = "1113113131"
CODE39(8)\Char = "8" : CODE39(8)\Def = "3113113111" 
CODE39(9)\Char = "9" : CODE39(9)\Def = "1133113111" 
CODE39(10)\Char = "A" : CODE39(10)\Def = "3111131131" 
CODE39(11)\Char = "B" : CODE39(11)\Def = "1131131131"
CODE39(12)\Char = "C" : CODE39(12)\Def = "3131131111" 
CODE39(13)\Char = "D" : CODE39(13)\Def = "1111331131" 
CODE39(14)\Char = "E" : CODE39(14)\Def = "3111331111"  
CODE39(15)\Char = "F" : CODE39(15)\Def = "1131331111" 
CODE39(16)\Char = "G" : CODE39(16)\Def = "1111133131"  
CODE39(17)\Char = "H" : CODE39(17)\Def = "3111133111"  
CODE39(18)\Char = "I" : CODE39(18)\Def = "1131133111"  
CODE39(19)\Char = "J" : CODE39(19)\Def = "1111333111"  
CODE39(20)\Char = "K" : CODE39(20)\Def = "3111111331"  
CODE39(21)\Char = "L" : CODE39(21)\Def = "1131111331"  
CODE39(22)\Char = "M" : CODE39(22)\Def = "3131111311"  
CODE39(23)\Char = "N" : CODE39(23)\Def = "1111311331"  
CODE39(24)\Char = "O" : CODE39(24)\Def = "3111311311"  
CODE39(25)\Char = "P" : CODE39(25)\Def = "1131311311"  
CODE39(26)\Char = "Q" : CODE39(26)\Def = "1111113331"  
CODE39(27)\Char = "R" : CODE39(27)\Def = "3111113311"  
CODE39(28)\Char = "S" : CODE39(28)\Def = "1131113311"  
CODE39(29)\Char = "T" : CODE39(29)\Def = "1111313311" 
CODE39(30)\Char = "U" : CODE39(30)\Def = "3311111131" 
CODE39(31)\Char = "V" : CODE39(31)\Def = "1331111131" 
CODE39(32)\Char = "W" : CODE39(32)\Def = "3331111111"  
CODE39(33)\Char = "X" : CODE39(33)\Def = "1311311131"  
CODE39(34)\Char = "Y" : CODE39(34)\Def = "3311311111"  
CODE39(35)\Char = "Z" : CODE39(35)\Def = "1331311111"  
CODE39(36)\Char = "-" : CODE39(36)\Def = "1311113131"  
CODE39(37)\Char = "." : CODE39(37)\Def = "3311113111" 
CODE39(38)\Char = " " : CODE39(38)\Def = "1331113111" 
CODE39(39)\Char = "$" : CODE39(39)\Def = "1313131111"  
CODE39(40)\Char = "/" : CODE39(40)\Def = "1313111311"  
CODE39(41)\Char = "+" : CODE39(41)\Def = "1311131311"  
CODE39(42)\Char = "%" : CODE39(42)\Def = "1113131311"  
CODE39(43)\Char = "*" : CODE39(43)\Def = "1311313111"  
;} -------------------------------

Procedure AscTo39(c.s) 
  AscTo39 = -1 
  If c >= "0" And c <= "9" 
    AscTo39 = Val(c) 
  Else 
    c = UCase(c) 
    If c >= "A" And c <= "Z" 
      AscTo39 = Asc(c) - 55 
    Else 
      Select c 
        Case "-" 
          AscTo39 = 36 
        Case "." 
          AscTo39 = 37 
        Case " " 
          AscTo39 = 38 
        Case "*" 
          AscTo39 = 43 
        Case "$" 
          AscTo39 = 39 
        Case "/" 
          AscTo39 = 40 
        Case "+" 
          AscTo39 = 41 
        Case "%" 
          AscTo39 = 42 
      EndSelect 
    EndIf 
  EndIf 
  ProcedureReturn AscTo39 
EndProcedure 

Procedure.f CreateCodeBar39(x.f, y.f, h.f, wf.f, text.s, tf.b) 
  DefType.f xpos, ypos
  xpos = x ; Offset von Links
  ypos = y ; Offset von oben
  wf = wf * 0.1 ; Breite eines Balkens 
  chrspace.f = wf*16
  text = "*"+Trim(text)+"*"
  width.f = Len(text)*wf*16 ; 1 BarUnit = 16 * BarWidth
  If tf : height.f = h + #CharH : Else : height.f = h :  EndIf
  For tpos = 1 To Len(text) 
    char$ = Mid(text, tpos, 1) 
    N39 = AscTo39(char$) 
    For dpos = 1 To 10 Step 2
      ; Draw line for bar -----------
      w.f = Val(Mid(CODE39(N39)\Def, dpos, 1)) ; BarWidth 
      pdf_Rect(xpos, ypos, w * wf, h, #PDF_STYLE_FILL)
      xpos + (w * wf)
      ; Space ----------- 
      xpos + Val(Mid(CODE39(N39)\Def, dpos+1, 1)) * wf
      ; Text ----------
      If tf ; Human Readable 
        pdf_SetXY(x+chrspace*(tpos-1), ypos + h)
        pdf_Cell(chrspace, #CharH , UCase(char$), 0, 0, #PDF_ALIGN_CENTER)
      EndIf
    Next 
  Next
EndProcedure 
; =========================

; Parameter:
; x (mm) / y (mm) / Höhe (mm) / Breite der Balken (2 => 0.2mm) / Text / 0 = nur Barcode, 1 = mit Text

; Start PDF ------------
pdf_Create("p", "mm")
pdf_AddPage()
pdf_SetFont("Arial","",10)
; ------------------------------

CreateCodeBar39(20, 20, 15, 2, "Barcode Code39", 1)

; End PDF --------------
pdf_Save("BarCode.pdf")
;  -------------------------
Download of PureBasic - Module
Download of PureBasic - Programmes

[Windows 11 x64] [PB V6]

Bild