I'm trying to create a pdf file inside my app, save it on the external storage the open it. Saving a file isn't an issue for me, nor is opening one, my issue is with creating one and writing in it. So after some research online I found the following way of doing it:
File file = new File(directoryName, fileName);
// Creating output stream to write in the newly created file
FileOutputStream fOut = null;
try {
fOut = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
// Creating a new document
Document document = new Document(PageSize.A4, 50, 50, 50, 50);
try {
PdfWriter.getInstance(document, fOut);
// Open the document for writing
document.open();
// Write in the document
document.add(new Paragraph("Hello world"));
document.close();
} catch (DocumentException de) {
System.err.println(de.getMessage());
}
Upon running my app and executing the code above, I get the following error:
java.lang.NoClassDefFoundError: Failed resolution of: Ljava/awt/Color;
Would someone know what's the issue with my code, or of another way that is sure to work for creating and writing a pdf file ?
Thanks !
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…