Tôi cố gắng trích xuất hình ảnh từ pdf bằng cách sử dụng pdfbox. Ví dụ pdf heretrích xuất hình ảnh từ pdf bằng cách sử dụng pdfbox
Nhưng tôi chỉ nhận được hình ảnh trống.
Mã i đang cố gắng: -
public static void main(String[] args) {
PDFImageExtract obj = new PDFImageExtract();
try {
obj.read_pdf();
} catch (IOException ex) {
System.out.println("" + ex);
}
}
void read_pdf() throws IOException {
PDDocument document = null;
try {
document = PDDocument.load("C:\\Users\\Pradyut\\Documents\\MCS-034.pdf");
} catch (IOException ex) {
System.out.println("" + ex);
}
List pages = document.getDocumentCatalog().getAllPages();
Iterator iter = pages.iterator();
int i =1;
String name = null;
while (iter.hasNext()) {
PDPage page = (PDPage) iter.next();
PDResources resources = page.getResources();
Map pageImages = resources.getImages();
if (pageImages != null) {
Iterator imageIter = pageImages.keySet().iterator();
while (imageIter.hasNext()) {
String key = (String) imageIter.next();
PDXObjectImage image = (PDXObjectImage) pageImages.get(key);
image.write2file("C:\\Users\\Pradyut\\Documents\\image" + i);
i ++;
}
}
}
}
Cảm ơn
Tôi gặp sự cố khi kiểm tra mã của bạn: "UnsupportedOper" –
Bạn có thấy câu trả lời về cách giải mã hình ảnh JBIG2 không? – MyTitle
liên kết tới PDF đã chết –