fonts - Adobe Acrobat 表单文本字段中的 Code128 条码
问题描述
我们有一个 PDF 表单,您可以在其中填写产品选项,然后将这些选项转换为单个文本字段“批号”,最后是一个字段“批号条形码”,获取批号并将其转换为条形码。由于某种原因,这不起作用。我对条形码集成几乎一无所知,但我是一名程序员,只是在寻找有关此主题的一些指导。
“批号条形码”字段在属性计算->自定义计算脚本下使用此代码。所以就像我上面说的那样,它采用“批号”字段并转换为我相信的字符串,然后字体用来生成正确的条形码,或者这就是想法。
event.value = this.getField("Lot No").valueAsString;
这是我从客户那里得到的实际 PDF 的链接:
https ://ufile.io/ihh87
这就是我在这个主题上发现的,但显然仍然缺少拼图的部分,希望有人能给我在 Acrobat Pro 中完成这项工作所需的确切步骤。
- 我需要可嵌入的 CODE 128 字体吗?我找到了这个字体集,但价格为 159 美元。有没有我可以使用并且仍然可以使用的免费版本? https://www.idautomation.com/barcode-fonts/code-128/
- Javascript - 我需要将自定义 Javascript 代码添加到“Lot Number Barcode”文本字段的 Actions 属性中,但我不知道需要实现哪些代码,并在此寻找资源以更好地解释该过程。
- 字体高度和字体大小 - 如果我让前两个步骤正常工作,我仍然需要关注将 PDF 文本字段设置为精确的字体大小和高度,否则条形码扫描仪可能会出错。这是真的?目前 PDF 文本字段字体大小设置为“自动”
解决方案
您可以在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>
Font Size:
<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>
<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 的余数。
推荐阅读
- git - 删除未跟踪的文件但不将其从硬盘中删除
- dialogflow-es - 如何处理谷歌操作对话框流中的重复唤醒词?
- opencart - 致命错误:在中找不到类“Htmlfilter”
- javascript - 如何制作移动响应式垂直范围滑块
- python - 没有名为“pyscipopt”的模块
- netty - 什么是 Netty DecoderResult 以及如何使用它?
- php - 如何使用正文发送 HTTP 响应 200 OK?
- javascript - 如何在 Angular 的 chrome 浏览器中捕获控制台日志
- javascript - VueJS/nuxt 'state' 应该是在 store/store.js 中返回对象的方法
- event-b - Event-B 总功能证明义务