- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 iText API 生成条形码,当它是线性条形码时,一切看起来都很好,当它是二维条形码时,条形码作为图像放入 pdf 文档中,因此降低了低分辨率打印机上条形码的质量并且无法扫描条码。下面是代码
BarcodePDF417 pdf417 = new BarcodePDF417();
String text = "BarcodePDF417 barcode";
pdf417.setText(text);
Image img = pdf417.getImage();
document.add(img);
现在我正在寻找绘制条形码的替代方法,我发现 palceBarcode 方法可能有利于需求。
我在 itext 源代码的 BarcodePDF417 类中看到了下面的代码,但无法找到如何使用它的方法
public void placeBarcode(PdfContentByte cb, BaseColor foreground, float moduleHeight, float moduleWidth) {
paintCode();
int stride = (bitColumns + 7) / 8;
cb.setColorFill(foreground);
for (int k = 0; k < codeRows; ++k) {
int p = k * stride;
for (int j = 0; j < bitColumns; ++j) {
int b = outBits[p + j / 8] & 0xff;
b <<= j % 8;
if ((b & 0x80) != 0) {
cb.rectangle(j * moduleWidth, (codeRows - k - 1) * moduleHeight, moduleWidth, moduleHeight);
}
}
}
cb.fill();
}
谁能推荐一下上述方法的使用方法?
我写了如下代码,但整个页面变黑了。
Rectangle pageSize = new Rectangle(w * 72, h * 72);
Document doc = new Document(pageSize, 1f, 1f, 1f, 1f);
PdfWriter writer = PdfWriter.getInstance(doc, getOutputStream());
doc.open();
PdfContentByte cb = writer.getDirectContent();
BarcodePDF417 pf = new BarcodePDF417();
pf.setText("BarcodePDF417 barcode");
pf.getImage();
Rectangle rc = pf.getBarcodeSize();
pf.placeBarcode(cb, BaseColor.BLACK, rc.getHeight(), rc.getWidth());
doc.close();
最佳答案
请看BarcodePlacement例子。在这个例子中,我们创建了三个 PDF417 条形码:
PdfContentByte cb = writer.getDirectContent();
Image img = createBarcode(cb, "This is a 2D barcode", 1, 1);
document.add(new Paragraph(
String.format("This barcode measures %s by %s user units",
img.getScaledWidth(), img.getScaledHeight())));
document.add(img);
img = createBarcode(cb, "This is NOT a raster image", 3, 3);
document.add(new Paragraph(
String.format("This barcode measures %s by %s user units",
img.getScaledWidth(), img.getScaledHeight())));
document.add(img);
img = createBarcode(cb, "This is vector data drawn on a PDF page", 1, 3);
document.add(new Paragraph(
String.format("This barcode measures %s by %s user units",
img.getScaledWidth(), img.getScaledHeight())));
结果在外面看起来是这样的:
一个特定的条形码在内部看起来像这样:
我添加此内部 View 以显示二维条形码未添加为光栅图像(与您尝试的初始方法一样)。它是由一系列小矩形组成的 vector 图像。您可以通过查看 barcode_placement.pdf 自行检查。文件。
请不要混淆,因为我使用的是 Image
目的。如果您查看 createBarcode()
方法,你可以看到Image
实际上是一个 vector 图像:
public Image createBarcode(PdfContentByte cb, String text,
float mh, float mw) throws BadElementException {
BarcodePDF417 pf = new BarcodePDF417();
pf.setText("BarcodePDF417 barcode");
Rectangle size = pf.getBarcodeSize();
PdfTemplate template = cb.createTemplate(
mw * size.getWidth(), mh * size.getHeight());
pf.placeBarcode(template, BaseColor.BLACK, mh, mw);
return Image.getInstance(template);
}
传递给 placeBarcode()
的高度和宽度方法,定义绘制的小矩形的高度和宽度。如果您查看 内部 View ,您可以看到例如:
0 21 3 1 re
这是一个 x = 0,y = 21,宽 3,高 1 的矩形。
当您询问条形码的大小时,您会得到将要绘制的矩形的数量。因此条形码的尺寸是:
Rectangle size = pf.getBarcodeSize();
float width = mw * size.getWidth();
float height = mh * size.getHeight();
您的假设 size
是用户单位的大小只有在 mw
时才是正确的和 mh
等于1
.
我使用这些值创建一个 PdfTemplate
实例,然后我将条形码绘制到此 Form XObject。大多数时候,使用 Image
更容易类比使用 PdfTemplate
,所以我包装了 PdfTemplate
在 Image
里面.
然后我可以添加这个 Image
就像任何其他图像一样添加到文档中。与普通图像的主要区别在于,该图像是 vector 图像。
关于java - Java中的二维条码生成问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30186774/
也许有一个简单的解决方案,但我似乎找不到,我需要在不增加字体大小的情况下增加条形码的高度。 // Barcode Text Block
当我使用code128.createImageWithBarcode()创建图像时,条形码下的文本出现在文档中,但是当我尝试使用createAwtImage创建图像并稍后将其保存到光盘时,条形码下的文
我一直在尝试获取 this库在我的 android 应用程序中工作,但我无法让它成功工作。我有 fragment 显示,相机显示正常,但它似乎没有扫描任何东西(QR、条形码等)。我已经实现了回调接口(
我正在使用 zebraGk420d 打印机。我正在使用垂直条形码标签。如何垂直打印文本和条形码。我的 zpl 代码是这样的 $barcode_ZPL_code="^XA ^FO 150,50^AD,4
我正在尝试创建一个简单的 EAN13 图像来显示字符串中的条形码。 我试过这段代码,但它只能生成一个code128。我可以使用什么来生成 EAN13? class Barcode { class
我尝试使用Zxing解码128C(代码集C)条形码。当我读取 QR_CODE、UPC_A 等其他类型时,我会成功。 这些是我尝试读取的条形码: 是否可以使用 Zxing 读取 128C 条码(非 CO
[已解决]这些应用程序运行良好,没有崩溃,但它应该将 resultView 文本从“Hasil Scan”更新为扫描结果,但事实并非如此。问题是 TextView (结果 View )在扫描后没有更新
我有一个项目,它绘制了一个价格标签,上面有一个条形码。要绘制条形码,我使用设置了 EAN-13 字体的 JLabel。生成价格标签的输入数据由两个条形码属性组成:条形码编号 080432402184
我正在我的应用程序中实现条形码扫描器。我想限制我的检测区域。遵循以下逻辑,但我在某些设备上无法正常工作。 //尝试裁剪框架的中心部分: public class BoxDetector extend
我正在尝试使用 ZXing 库来解码 Datamatrix 条码。这是我的代码示例: BufferedImage bi = img.getBufferedImage(); Hashtable hint
Data Matrix 条形码支持已添加到 iOS 8 中,我可以使用它来读取 Data Matrix 条形码,如果它们是白底黑字(暗色)。但是,它从不读取黑底白字(深色底色)条码。 读这个很好: 无
我有这段代码可以生成条形码: func generateBarcode(from string: String) -> UIImage? { let data = string.data(us
这个问题在这里已经有了答案: What is the actual HEX / binary value of the GS1 FNC1 character? (2 个答案) 关闭 4 年前。 如何
我需要用 code128 barcodes 生成标签在 PHP . 用户几乎可以使用任何打印机打印这些内容。 我有一些具体的要求: 窄条宽度应介于 0.375 毫米和 0.5 毫米之间 最大整体条码宽
我想从我的应用程序创建 Code39 编码的条形码。 我知道我可以为此使用字体,但我不想这样做,因为我必须在服务器上注册字体,而且我有一些非常糟糕的经历。 我在问这个问题后产生的一个例子是答案 最佳答
将零抑制的八位 GTIN-12 标识符(表示为 UPC-E 条形码)转换为 UPC-A 条形码中显示的完整十二位版本的算法是什么? 最佳答案 从以下模式映射可以最清楚地看出在 UPC-E 和 UPC-
HTML文件 进程.php $value = $_post['barcode_value']; 嗨, friend 们,我要为 Android 设备开发一个 Web 应用程序,如果我点击输入文本框
我有一个相当大的 XML 数据集,例如: … … … … … … Mon, 24 Aug 2015, 8:30am
我正在测试来自 android-vision 的条码 API repo (多跟踪器应用程序)。但我只能扫描二维码,我还想扫描一维条形码,如 EAN 13。我怎样才能做好这项工作?? Ps.: 另外,我
我想从 C# 程序创建 DataMatrix ECC200 条码。是否有关于如何将信息编码到条形码中的文档,或者是否有第 3 方程序集来实现此目的? 最佳答案 你看过iec16022sharp了吗?
我是一名优秀的程序员,十分优秀!