首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ITEXT作为字段标识符,在PDF中填充条形码PDF-417

使用ITEXT作为字段标识符,在PDF中填充条形码PDF-417
EN

Stack Overflow用户
提问于 2017-04-27 11:24:25
回答 1查看 1.7K关注 0票数 1

我需要生成一个PDF417条形码,并将其填充到一个PDF字段中,对于该字段,我使用ITEXT获得了归档标识符。

我使用了几种方法,例如

方法1

代码语言:javascript
复制
      PdfContentByte cb = stamper.getUnderContent(1);
      BarcodePDF417 pf = new BarcodePDF417();
      pf.setText("Some text value for encoding");
      Rectangle size = pf.getBarcodeSize();

      PdfTemplate template = cb.createTemplate(size.getWidth(), size.getHeight());
      pf.placeBarcode(template, BaseColor.BLACK, 5, 5);
      Image image = Image.getInstance(template);
      image.setAbsolutePosition(35f, 40f);
      cb.addImage(image);

这里的问题是条形码大小不合适,位置也不正确。

路2。

代码语言:javascript
复制
  BarcodePDF417 barcode = new BarcodePDF417();
  barcode.setText("Some text value for encoding");
  barcode.placeBarcode(cb, BaseColor.BLACK, 5, 5);

这里的问题也是一样的,条形码不是合适的大小,也没有放在正确的位置。

我知道文件的字段标识符,我需要具体地放置条形码。有什么方法可以让我得到这个单元格并生成这个单元格大小的条形码图像并将其放入其中吗?

谢谢你的帮助!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-05-07 07:42:05

我终于可以实现这一点了。我的代码是

代码语言:javascript
复制
        PdfContentByte cb = stamper.getUnderContent(i);// i being the pdf page number.
        BarcodePDF417 barcode = new BarcodePDF417();
        barcode.setErrorLevel(5);
        barcode.setCodeColumns(30);
        barcode.setCodeRows(5);
        barcode.setOptions(BarcodePDF417.PDF417_FIXED_RECTANGLE);
        barcode.setText(<Byte[] - aka byte array of the text that needs to be encoded.>);
        Rectangle rect = barcode.getBarcodeSize();

        PdfTemplate template = cb.createTemplate(2 + rect.getWidth(), 2 + rect.getHeight());

        barcode.placeBarcode(template, BaseColor.BLACK, 1, 1);

        Image image = Image.getInstance(template);
        image.scaleAbsolute(535, 135);
        image.setAbsolutePosition(40f, 40f);
        cb.addImage(image);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43656405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档