我试图使用PDFBox2.0.13在PDF中插入条形码。我尝试在How to add Code128 Barcode image to existing pdf using pdfbox(1.8.12) with barcode4j library?中使用BufferedImage,但这使用“新PDPixelMap(doc,bim)”这个PDPixelMap在2.0.x中已弃用。我的问题是我们如何使用PDFBox2.0.13中的API(可能是PDPixelMap的替代品)插入PDF中的条形码,而不使用PDPixelMap。如果提供的代码片段会很棒。
像这样使用LosslessFactory
:
PDImageXObject img = LosslessFactory.createFromImage(doc, bim);
contentStream.drawImage(img, x, y);