我正在尝试在我的应用程序中创建一个pdf文件,将其保存在打开它的外部存储器上.保存文件对我来说不是问题,也不是打开文件,我的问题是创建文件并写入文件.所以在网上进行一些研究后,我发现了以下方法:
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());
}
Run Code Online (Sandbox Code Playgroud)
运行我的应用程序并执行上面的代码后,我收到以下错误:
java.lang.NoClassDefFoundError: Failed resolution of: …Run Code Online (Sandbox Code Playgroud) 您好,我正在尝试使用iText库从 Recyclerview 创建 PDF 输出文件。经过几个小时的努力,我能够从 recyclerview 创建 PDF。
以下是我用来创建 PDF 的类
主类的代码
private void getPrint() {
ArrayList<View> viewArrayList = mAdapter.getPrintView(); // A function from Adapter class which returns ArrayList of VIEWS
Document document = new Document(PageSize.A4);
final File file = new File(getStorageDir("PDF"), "print.pdf");
try {
PdfWriter.getInstance(document, new FileOutputStream(file));
} catch (DocumentException | FileNotFoundException e) {
e.printStackTrace();
}
for (int im = 0; im < viewArrayList.size(); im++) {
// Iterate till the last of the array list and add each …Run Code Online (Sandbox Code Playgroud)