How to insert barcode in PDF using PDFBox 2.0.13?

问题: I am trying to insert barcode in the PDF using PDFBox2.0.13. I tried using the BufferedImage for this as given in How to add Code128 Barcode image to existing pdf using pdf...

问题:

I am trying to insert barcode in the PDF using PDFBox2.0.13. I tried using the BufferedImage for this as given in How to add Code128 Barcode image to existing pdf using pdfbox(1.8.12) with barcode4j library? but this uses "new PDPixelMap(doc, bim)" this PDPixelMap is deprecated in 2.0.x. My question is how do we insert barcode in PDF with APIs available in PDFBox2.0.13(probably replacement of PDPixelMap)and without using PDPixelMap.? Would be great if code snippet provided.


回答1:

Use LosslessFactory like this:

PDImageXObject img = LosslessFactory.createFromImage(doc, bim);
contentStream.drawImage(img, x, y);
  • 发表于 2019-02-13 18:58
  • 阅读 ( 169 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除