相关疑难解决方法(0)

以编程方式在android中创建pdf文件并在其中书写

我正在尝试在我的应用程序中创建一个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)

pdf android file itext android-pdf-api

10
推荐指数
3
解决办法
6万
查看次数

在 Android 中使用 Recyclerview(里面的整个项目)中的 iText 创建 PDF 文件?

您好,我正在尝试使用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)

java pdf android itext

2
推荐指数
1
解决办法
4215
查看次数

标签 统计

android ×2

itext ×2

pdf ×2

android-pdf-api ×1

file ×1

java ×1