Adobe Acrobat表单文本字段中的Code128条形码

问题描述 投票:0回答:3

我们有一个PDF表单,您可以在其中填写产品选项,然后将这些选项转换为单个文本字段“批号”,最后将字段“批号条形码”转换为批号并将其转换为条形码。由于某种原因,这是行不通的。我对条码集成几乎一无所知,但我是一名程序员,只是在寻找关于这个主题的一些指导。

“批号条形码”字段使用属性Calculate-> Custom Calculation Script此代码。就像我上面说的那样,它取“批号”字段并转换为字符串,我相信字体用于生成正确的条形码或者这个想法。

event.value = this.getField("Lot No").valueAsString;

这是我从客户端提供的实际PDF的链接: https://ufile.io/ihh87

这是我在这个主题上发现的,但显然仍然缺少拼图的部分,并希望有人可以给我在Acrobat Pro中使用它所需的确切步骤。

  1. 我需要一个可嵌入的CODE 128字体?我发现这个字体集,但成本$ 159是否有我可以使用的免费版本并让它仍然有效? https://www.idautomation.com/barcode-fonts/code-128/
  2. Javascript - 我需要将自定义Javascript代码添加到“批号条形码”文本字段的“操作”属性中,但我不知道需要实现哪些代码并在此处查找资源以更好地解释该过程。
  3. 字体高度和字体大小 - 如果我前两步工作,我仍然需要关注将PDF文本字段设置为精确的字体大小和高度,否则条形码扫描器可能会出错。这是真的?目前PDF文本字段字体大小设置为“自动”
fonts barcode acrobat code128
3个回答
1
投票

代码128是相对复杂的条形码,并且不能通过用字体替换要替换的字符串来表示。因此,您需要一些逻辑来组合要显示的正确字符串。我不知道公开的任何可以进行计算的东西;你是独自一人还是必须找人帮忙。

为了创建该逻辑,您必须了解Code 128的工作原理;这些信息应该是免费提供的。

关于字体许可证,您可以将其成本与其他解决方案进行比较:尝试使用浮动的自由字体,或创建自己的字体,或使用图形(例如在注释中,可以使用Acrobat JavaScript计算)。在一天结束时,即使是相当昂贵的字体也可能是最经济的解决方案。

由于您已经研究过Code 128的规范,您还将看到打印它的要求。您必须使用字段进行调整,并且很可能必须设置固定的字体大小。但是,这将取决于打印页面时发生的缩放。


1
投票

您可以在https://fonts.googleapis.com/css?family=Libre+Barcode+128+Text上尝试Libre Code128字体(免费),以及附加的JavaScript代码来计算校验和。

var buttonGen = document.getElementById("btnGen");
buttonGen.onclick = function () {
  var x = document.getElementById("textIn").value;
  var i, j, intWeight, intLength, intWtProd = 0, arrayData = [], fs;
  var arraySubst = [ "Ã", "Ä", "Å", "Æ", "Ç", "È", "É", "Ê" ];

/*
 * Checksum Calculation for Code 128 B
 */
  intLength = x.length;
	arrayData[0] = 104; // Assume Code 128B, Will revise to support A, C and switching.
	intWtProd = 104;
	for (j = 0; j < intLength; j += 1) {
			arrayData[j + 1] = x.charCodeAt(j) - 32; // Have to convert to Code 128 encoding
			intWeight = j + 1; // to generate the checksum
			intWtProd += intWeight * arrayData[j + 1]; // Just a weighted sum
	}
	arrayData[j + 1] = intWtProd % 103; // Modulo 103 on weighted sum
	arrayData[j + 2] = 106; // Code 128 Stop character
  chr = parseInt(arrayData[j + 1], 10); // Gotta convert from character to a number
  if (chr > 94) {
    chrString = arraySubst[chr - 95];
  } else {
    chrString = String.fromCharCode(chr + 32);
  }
  
  // Change the font-size style to match the drop down
  fs = document.getElementsByTagName("option")[document.getElementById("selList").selectedIndex].value;
  document.getElementById("test").style.fontSize = fs  + 'px';
  
  document.getElementById("check").innerHTML =
    'Checksum = ' + chr + ' or character ' + // Make It Visual
    chrString + ', for text = "' + x + '"';
  
  document.getElementById("test").innerHTML =
    'Ì' + // Start Code B
    x + // The originally typed string
    chrString + // The generated checksum
    'Î'; // Stop Code
}
<html>
  <head>
    <link href="https://fonts.googleapis.com/css?family=Libre+Barcode+128+Text" rel="stylesheet">
    <style>
      td, th {
        text-align: center;
        padding: 6px;
      }

      .ss {
        font-family: 'Libre Barcode 128 Text', cursive;
        font-size: 24px;
      }
    </style>
  </head>
  <body>
    &nbsp;Font Size:&nbsp;
    <select id="selList">
      <option value="24" selected>24px</option>
      <option value="30">30px</option>
      <option value="36">36px</option>
      <option value="42">42px</option>
      <option value="48">48px</option>
      <option value="54">54px</option>
      <option value="60">60px</option>
      <option value="66">66px</option>
      <option value="72">72px</option>
      <option value="78">78px</option>
      <option value="84">84px</option>
      <option value="90">90px</option>
      <option value="96">96px</option>
    </select>&nbsp;

    <input type="text" id="textIn"></input>
    <input type="button" id="btnGen" value="Generate Code 128 Checksum" tabindex=4/>
    <div id="check"></div><br /><span id="test" class="ss">ÌMaking the Web Beautiful!$Î</span><br />
    <p>This is a demonstration of use of the Libre Barcode 128 Font.</p>
    <p>Because the Libre Barcode Code 128 font does not generate checksums, you need this component to produce a scanning barcode.</p>
    <p>To use, just enter the text you want to embed in the barcode and press the generate button. Happy barcoding!</p>
    <p>By the way, Libre Barcode 128 Font uses the following high ASCII / unicode characters to implement the control codes symbols. (This is essentially adding 100 to the value, in other words 'Ã' is U+00C3 (195) to 'Î' is U+00CE (206).)</p>
<table border="3">
    <tr>
    <th>Value</th>
    <th>Encoding</th>
    <th>Subst</th>
  </tr>
<tr><td> 95</td><td>A: US, B: DEL, C: 95</td><td>Ã</td></tr>
<tr><td> 96</td><td>A: FNC 3, B: FNC 3, C: 96</td><td>Ä</td></tr>
<tr><td> 97</td><td>A: FNC 2, B: FNC 2, C: 97</td><td>Å</td></tr>
<tr><td> 98</td><td>A: Shift B, B: Shift A, C: 98</td><td>Æ</td></tr>
<tr><td> 99</td><td>A: Code C, B: Code C, C: 99</td><td>Ç</td></tr>
<tr><td>100</td><td>A: Code B, B: FNC 4, C: Code B</td><td>È</td></tr>
<tr><td>101</td><td>A: FNC 4, B: Code A, C: Code A</td><td>É</td></tr>
<tr><td>102</td><td>A: FNC 1, B: FNC 1, C: FNC 1</td><td>Ê</td></tr>
<tr><td>103</td><td>Begin Code A</td><td>Ë</td></tr>
<tr><td>104</td><td>Begin Code B</td><td>Ì</td></tr>
<tr><td>105</td><td>Begin Code C</td><td>Í</td></tr>
<tr><td>106</td><td>Stop Code</td><td>Î</td></tr></table>
  </body>
</html>

为了获得Code 128条形码进行打印和扫描,需要计算校验和。这涉及计算批号内容的加权和并将其除数的余数推导出103。


0
投票

libre barcode128字体似乎是条形码字体ID系列的开源副本。所以字符代码可能匹配。

优化的128个代码(在Code128B和128C之间切换以允许在输入字符串中使用连续数字时更短的条形码)将不是非常易读的,因此使用包含人类可读字符的字体将不会产生很好的结果,因为Code128C编码(对于数字)将会连续编号。

我找到了这个librebarcode project on github,其中有人使用了一个大的javascript数组,字符映射的字体和你应该用于计算校验和的权重。

与示例代码和the wikipedia page for code 128一起,您应该能够在Acrobat中获得一些工作。

这是数组:

var data = [
      // the unicode chars are from:
      //   www.idautomation.com/barcode-fonts/code.128/user-manual.html
      //   http://www.jtbarton.com/Barcodes/Code128.aspx
      // checksum value, pattern, canonical id/name (based on Code Set B)
      // (name of the glyph in the font?), [unicode chars], textbelow_flag_or_charcodes
      [   0, ' ', ' ', '00', 'Â']
    , [   1, '!', '!', '01', '!']
    , [   2, '"', '"', '02', '"']
    , [   3, '#', '#', '03', '#']
    , [   4, '$', '$', '04', '$']
    , [   5, '%', '%', '05', '%']
    , [   6, '&', '&', '06', '&']
    , [   7, "'", "'", "07", "'"]
    , [   8, '(', '(', '08', '(']
    , [   9, ')', ')', '09', ')']
    , [  10, '*', '*', '10', '*']
    , [  11, '+', '+', '11', '+']
    , [  12, ',', ',', '12', ',']
    , [  13, '-', '-', '13', '-']
    , [  14, '.', '.', '14', '.']
    , [  15, '/', '/', '15', '/']
    , [  16, '0', '0', '16', '0']
    , [  17, '1', '1', '17', '1']
    , [  18, '2', '2', '18', '2']
    , [  19, '3', '3', '19', '3']
    , [  20, '4', '4', '20', '4']
    , [  21, '5', '5', '21', '5']
    , [  22, '6', '6', '22', '6']
    , [  23, '7', '7', '23', '7']
    , [  24, '8', '8', '24', '8']
    , [  25, '9', '9', '25', '9']
    , [  26, ':', ':', '26', ':']
    , [  27, ';', ';', '27', ';']
    , [  28, '<', '<', '28', '<']
    , [  29, '=', '=', '29', '=']
    , [  30, '>', '>', '30', '>']
    , [  31, '?', '?', '31', '?']
    , [  32, '@', '@', '32', '@']
    , [  33, 'A', 'A', '33', 'A']
    , [  34, 'B', 'B', '34', 'B']
    , [  35, 'C', 'C', '35', 'C']
    , [  36, 'D', 'D', '36', 'D']
    , [  37, 'E', 'E', '37', 'E']
    , [  38, 'F', 'F', '38', 'F']
    , [  39, 'G', 'G', '39', 'G']
    , [  40, 'H', 'H', '40', 'H']
    , [  41, 'I', 'I', '41', 'I']
    , [  42, 'J', 'J', '42', 'J']
    , [  43, 'K', 'K', '43', 'K']
    , [  44, 'L', 'L', '44', 'L']
    , [  45, 'M', 'M', '45', 'M']
    , [  46, 'N', 'N', '46', 'N']
    , [  47, 'O', 'O', '47', 'O']
    , [  48, 'P', 'P', '48', 'P']
    , [  49, 'Q', 'Q', '49', 'Q']
    , [  50, 'R', 'R', '50', 'R']
    , [  51, 'S', 'S', '51', 'S']
    , [  52, 'T', 'T', '52', 'T']
    , [  53, 'U', 'U', '53', 'U']
    , [  54, 'V', 'V', '54', 'V']
    , [  55, 'W', 'W', '55', 'W']
    , [  56, 'X', 'X', '56', 'X']
    , [  57, 'Y', 'Y', '57', 'Y']
    , [  58, 'Z', 'Z', '58', 'Z']
    , [  59, '[', '[', '59', '[']
    , [  60, '\\', '\\', '60', '\\']
    , [  61, ']', ']', '61', ']']
    , [  62, '^', '^', '62', '^']
    , [  63, '_', '_', '63', '_']
    , [  64, 'NUL', '`', '64', '`']
    , [  65, 'SOH', 'a', '65', 'a']
    , [  66, 'STX', 'b', '66', 'b']
    , [  67, 'ETX', 'c', '67', 'c']
    , [  68, 'EOT', 'd', '68', 'd']
    , [  69, 'ENQ', 'e', '69', 'e']
    , [  70, 'ACK', 'f', '70', 'f']
    , [  71, 'BEL', 'g', '71', 'g']
    , [  72, 'BS', 'h', '72', 'h']
    , [  73, 'HT', 'i', '73', 'i']
    , [  74, 'LF', 'j', '74', 'j']
    , [  75, 'VT', 'k', '75', 'k']
    , [  76, 'FF', 'l', '76', 'l']
    , [  77, 'CR', 'm', '77', 'm']
    , [  78, 'SO', 'n', '78', 'n']
    , [  79, 'SI', 'o', '79', 'o']
    , [  80, 'DLE', 'p', '80', 'p']
    , [  81, 'DC1', 'q', '81', 'q']
    , [  82, 'DC2', 'r', '82', 'r']
    , [  83, 'DC3', 's', '83', 's']
    , [  84, 'DC4', 't', '84', 't']
    , [  85, 'NAK', 'u', '85', 'u']
    , [  86, 'SYN', 'v', '86', 'v']
    , [  87, 'ETB', 'w', '87', 'w']
    , [  88, 'CAN', 'x', '88', 'x']
    , [  89, 'EM', 'y', '89', 'y']
    , [  90, 'SUB', 'z', '90', 'z']
    , [  91, 'ESC', '{', '91', '{']
    , [  92, 'FS', '|', '92', '|']
    , [  93, 'GS', '}', '93', '}']
    , [  94, 'RS', '~', '94', '~']
    , [  95, 'US', 'DEL', '95 ', 'Ã']
    , [  96, 'FNC 3', 'FNC 3', '96', 'Ä']
    , [  97, 'FNC 2', 'FNC 2', '97', 'Å']
    , [  98, 'Shift B', 'Shift A', '98', 'Æ']
    , [  99, 'Code C', 'Code C', '99', 'Ç']
    , [ 100, 'Code B', 'FNC 4', 'Code B', 'È']
    , [ 101, 'FNC 4', 'Code A', 'Code A', 'É']
    , [ 102, 'FNC 1', 'FNC 1', 'FNC 1', 'Ê']
    , [ 103, 'Start Code A', 'Start Code A', 'Start Code A', 'Ë']
    , [ 104, 'Start Code B', 'Start Code B', 'Start Code B', 'Ì']
    , [ 105, 'Start Code C', 'Start Code C', 'Start Code C', 'Í']
    , [ 206, 'Stop', 'Stop', 'Stop', 'Î']
    ]
;

如果你想尝试,我自己的semi-working experiment is up on GitHub

© www.soinside.com 2019 - 2024. All rights reserved.