java Java打印条码标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1306134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-29 16:03:02  来源:igfitidea点击:

Java print barcode labels

javatemplatesprintinglabelbarcode

提问by David Hamilton

Can someone point in the right direction for printing barcode labels using Java? I can use the barbecue library (http://barbecue.sourceforge.net/) to generate them bar codes as images, but I need a way to put the image (and human readable caption) into an Avery document template for printing.

有人可以指出使用 Java 打印条形码标签的正确方向吗?我可以使用烧烤库 ( http://barbecue.sourceforge.net/) 将它们的条形码生成为图像,但我需要一种方法将图像(和人类可读的标题)放入 Avery 文档模板中进行打印。

回答by lucasmo

The iText library supports pretty much every kind of barcode imaginable. You can generate pdfs and either save them or print them internally.

iText 库支持几乎所有可以想象的条形码。您可以生成 pdf 并在内部保存或打印它们。

回答by therobyouknow

I suggest using the barcode4j library instead of barbecue for 2 reasons:

我建议使用barcode4j 库而不是烧烤有两个原因:

  1. Barbecue barcode objects are unnecessarily coupled to Java UI components (e.g. Barcode class extends JComponent). This creates unnecessary dependencies if the Java UI is not being used, e.g. for batch or command line based applications. They should have used aggregation rather than inheritance if they wanted to use their barcode classes with the Java UI.

  2. Barcode4J looks like it is currently supported - version 2.0 released and copyright date is 2012

  1. 烧烤条码对象不必要地耦合到 Java UI 组件(例如 Barcode 类扩展 JComponent)。如果未使用 Java UI,例如对于基于批处理或命令行的应用程序,这会创建不必要的依赖项。如果他们想在 Java UI 中使用他们的条形码类,他们应该使用聚合而不是继承。

  2. Barcode4J 看起来目前受支持 - 2.0 版已发布,版权日期为 2012

Then you have the problem of translating the barcode into a format that your printer understands. For this I suggest openlabelprint.org (which I wrote!)- it's another open source project that uses barcode4j and provides:

那么您就会遇到将条形码转换为打印机可以理解的格式的问题。为此,我建议使用 openlabelprint.org (我写的!)——它是另一个使用barcode4j 的开源项目,并提供:

  • facilities to define a label layout using SVG (Scalable Vector Graphics - an open w3c standard) and

  • rasterization to a bitmap of the SVG from barcode4j (and the surrounding label layout in SVG) (openlabelprint applies the excellent Apache SVG Batik Java libraries for rasterization as well as for other SVG tasks)

  • printing of the bitmap on Zebra printers using their ZPL low level language. openlabelprint has a built in utility to convert png bitmaps to ZPL and send this to the Zebra printer via the standard Java printer system. Also openlabelprint provides APIs to extend it for other printer languages though ZPL is supported by some non-Zebra brands

  • 使用 SVG(可缩放矢量图形 - 一个开放的 w3c 标准)定义标签布局的工具和

  • 从barcode4j(以及SVG中的周围标签布局)光栅化到SVG的位图(openlabelprint应用优秀的Apache SVG Batik Java库进行光栅化以及其他SVG任务)

  • 使用 ZPL 低级语言在 Zebra 打印机上打印位图。openlabelprint 有一个内置实用程序,可将 png 位图转换为 ZPL,并通过标准 Java 打印机系统将其发送到 Zebra 打印机。尽管某些非 Zebra 品牌支持 ZPL,但 openlabelprint 还提供 API 以将其扩展到其他打印机语言

回答by Philippe Carriere

I'm printing bar codes using java but I'm using a printer which have a pre-programmed function for printing bar codes. So I'm only telling the printer what codes to print and it does the rest. If you willing to pay for a printer it might saves you some time.

我正在使用 java 打印条形码,但我使用的打印机具有用于打印条形码的预编程功能。所以我只告诉打印机要打印哪些代码,剩下的由它来完成。如果您愿意为打印机付费,它可能会为您节省一些时间。

This may or may not be useful to you, but I thought i'd mention it.

这对你可能有用也可能没用,但我想我会提到它。

回答by Scott W

I think you will have to measure your Avery label page with a ruler and then in your Java code, you will have to create a full Letter/A4/whatever page to print and offset your barcode image on that page to the appropriate location based on your measurements with the ruler.

我认为你必须用尺子测量你的 Avery 标签页面,然后在你的 Java 代码中,你必须创建一个完整的 Letter/A4/任何页面来打印和偏移该页面上的条形码图像到适当的位置基于你用尺子测量。

回答by Vincnetas

Have you tried printing the image that you got from "barbecue" ?

您是否尝试过打印从“烧烤”中获得的图像?

回答by Steven Lizarazo

You should try JZebra this is an applet and a good start point for you, take a look at the java source code.

你应该试试 JZebra 这是一个小程序,对你来说是一个很好的起点,看看 java 源代码。

http://code.google.com/p/jzebra/

http://code.google.com/p/jzebra/

For zebra you this simple guide will help you. On this Zebra commands

对于斑马你,这个简单的指南将帮助你。在这个 Zebra 命令上

N
q609
Q203,26
B26,26,0,UA0,2,2,152,B,"777777"
A253,56,0,3,1,1,N,"JHON3:16"
A253,26,0,3,1,1,N,"JESUSLOVESYOU"
A253,86,0,3,1,1,N,"TEST TEST TEST"
A253,116,0,3,1,1,N,"ANOTHER TEST"
A253,146,0,3,1,1,N,"SOME LETTERS"
P1,1

on JZebra

在 JZebra 上

     var applet = document.jzebra;
     if (applet != null) {
applet.append("N\n");
applet.append("q609\n");
applet.append("Q203,26\n");
 applet.append("B26,26,0,UA0,2,2,152,B,\"777777\"\n");
applet.append("A253,56,0,3,1,1,N,\"JHON3:16\"\n");
applet.append("A253,26,0,3,1,1,N,\"JESUSLOVESYOU\"\n");
applet.append("A253,86,0,3,1,1,N,\"TEST TEST TEST\"\n");
applet.append("A253,116,0,3,1,1,N,\"ANOTHER TEST\"\n");
applet.append("A253,146,0,3,1,1,N,\"SOME LETTERS\"\n");
applet.append("P1,1\n");}

Having clear this:

清楚这一点:

EPL is one command per line. A command starts out with a command identifier, typically a letter, followed by a comma-separated list of parameters specific to that command. You can look up each of these commands in the EPL2 programming documentation. Here's an English-language version of the commands in the above example.

EPL 是每行一个命令。命令以命令标识符开头,通常是一个字母,后跟以逗号分隔的特定于该命令的参数列表。您可以在 EPL2 编程文档中查找这些命令中的每一个。这是上述示例中命令的英文版本。

  1. Sending an initial newline guarantees that any previous borked command is submitted.
  2. [N] Clear the image buffer. This is an important step and generally should be the first command in any EPL document; who knows what state the previous job left the printer in.
  3. [q] Set the label width to 609 dots (3 inch label x 203 dpi = 609 dots wide).
  4. [Q] Set the label height to 203 dots (1 inch label) with a 26 dot gap between the labels. (The printer will probably auto- sense, but this doesn't hurt.)
  5. [B] Draw a UPC-A barcode with value "777777" at x = 26 dots (1/8 in), y = 26 dots (1/8 in) with a narrow bar width of 2 dots and make it 152 dots (3/4 in) high. (The origin of the label coordinate system is the top left corner of the label.)
  6. [A] Draw the text "JESUSLOVESYOU" at x = 253 dots (3/4 in), y = 26 dots (1/8 in) in printer font "3", normal horizontal and vertical scaling, and no fancy white-on-black effect.
  1. 发送初始换行符可确保提交任何先前的 borked 命令。
  2. [N] 清除图像缓冲区。这是一个重要的步骤,通常应该是任何 EPL 文档中的第一个命令;谁知道上一个作业让打印机处于什么状态。
  3. [q] 将标签宽度设置为 609 点(3 英寸标签 x 203 dpi = 609 点宽)。
  4. [Q] 将标签高度设置为 203 点(1 英寸标签),标签之间有 26 点间距。(打印机可能会自动感应,但这不会造成伤害。)
  5. [B] 在 x = 26 点(1/8 英寸),y = 26 点(1/8 英寸)处绘制一个值为“777777”的 UPC-A 条码,条宽为 2 点,并使其为 152 点( 3/4 英寸)高。(标签坐标系的原点是标签的左上角。)
  6. [A] 在 x = 253 点(3/4 英寸),y = 26 点(1/8 英寸)处以打印机字体“3”绘制文本“JESUSLOVESYOU”,水平和垂直缩放正常,没有花哨的白色-黑色效果。

All tha A starting lines are similar. 10. [P] Print one copy of one label.

所有 tha A 起跑线都是相似的。10. [P] 打印一份标签。