我正在尝试使用PDFBox2.0.13在PDF中插入条形码。我尝试为此使用BufferedImage How to add Code128 Barcode image to existing pdf using pdfbox(1.8.12) with barcode4j library? 但这使用的是“新PDPixelMap(doc,bim)”,此PDPixelMap在2.0.x中已弃用。 我的问题是,如何在不使用PDPixelMap的情况下使用PDFBox2.0.13(可能是PDPixelMap的替代品)中可用的API在PDF中插入条形码?如果提供代码段,那就太好了。
答案 0 :(得分:0)
像这样使用LosslessFactory
:
PDImageXObject img = LosslessFactory.createFromImage(doc, bim);
contentStream.drawImage(img, x, y);