0
嘗試將PDF頁面的NoClassDefFoundError在PDFBox的添加圖像到PDF頁面的Android
PDDocument document = null;
File inputFile = new File(mFilePath);
document = PDDocument.load(inputFile);
PDPage page = document.getPage(0);
File image = new File("/storage/emulated/0/", "1.jpg");
PDImageXObject img = JPEGFactory.createFromStream(document, inputStream);
PDPageContentStream contentStream = new PDPageContentStream(document, page);
contentStream.drawImage(img, 100, 100);
contentStream.close();
File outputFile = new File(inputFile.getParent(), "new file.pdf");
document.save(outputFile);
document.close();
上寫的圖像,但得到此異常:
java.lang.NoClassDefFoundError: Failed resolution of: Ljavax/imageio/ImageIO;
at org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory.readJPEG(JPEGFactory.java:99)
at org.apache.pdfbox.pdmodel.graphics.image.JPEGFactory.createFromStream(JPEGFactory.java:78)
注:我也曾嘗試使用
PDImageXObject img = PDImageXObject.createFromFile(image.getPath(), document);
但沒有什麼不同的事。 我能做些什麼來將圖像添加到當前頁面中的位置,無一例外? (如果你知道更好的soloution讓我知道)
「鏈接,以回答」通不通。也許你的意思是https://stackoverflow.com/questions/8980668/how-to-add-pdfbox-to-an-android-project-or-suggest-alternative –
@TilmanHausherr:感謝您的通知,我糾正了網址到答案。 –