简体   繁体   中英

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 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.

Use LosslessFactory like this:

PDImageXObject img = LosslessFactory.createFromImage(doc, bim);
contentStream.drawImage(img, x, y);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM