问题
I am using PDFBox and have the following code snippet, which is reading a PDF file and converting it to image (PNG). It is working well, the only problem is that it is completely losing the barcode value that is in the PDF file.
Does anyone know how to work around this with PDFBox? Is that even possible? Thanks.
PDDocument doc = PDDocument.load(new File("INPUT.pdf"));
PDPage page = (PDPage) doc.getDocumentCatalog().getAllPages().get(0);
BufferedImage image = page.convertToImage();
File outputfile = new File("image.png");
ImageIO.write(image, "png", outputfile);
回答1:
The barcode image is in a format that is not recognized by pdfbox. You are missing some optional extensions like these:
- Reading JBIG2 images: JBIG2 ImageIO or JBIG2-Image-Decoder
- Reading JPEG 2000 (JPX) images: JAI Image I/O Tools Core
More information here.
来源:https://stackoverflow.com/questions/22028433/pdfbox-pdf-to-image-losing-barcode