4

我是 android 应用程序开发的新手。使用 iText 我已经在创建的文件上完成了 PDF 创建 n 写入,现在我想读取该 PDF 文件。如何使用 iText 打开或阅读 PDF 文件。

例子将是可观的..

然后提前……!!!

哪个是渲染 PDF 文件的最佳库..???? JPedal / iText / gnujpdf 或任何其他.....?????

4

2 回答 2

7

实际上,iText 仅用于创建 PDF,它不包含查看器部分。因此,您需要选择其他库。您可以按照 Azharahmed 提供的链接查找一些有用的库。

于 2012-02-15T10:51:45.567 回答
3

You can create your own PDF Viewer using iText, you can fetch Images for the specific page and simply display that image in a Scroll View.
But for using this approach, you will have to implement an efficient cache and set the specific pages threshold that will be made on initial run and progressively.
Here is the link, that will facilitate you:

public void makeImageFromPDF throws DocumentException,
        IOException {

    String INPUTFILE = Environment.getExternalStorageDirectory()
            .getAbsolutePath()+"/YOUR_DIRECTORY/inputFile.pdf";
    String OUTPUTFILE = Environment.getExternalStorageDirectory()
            .getAbsolutePath()+"/YOUR_DIRECTORY/outputFile.pdf";


    Document document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(OUTPUTFILE));
    document.open();

    PdfReader reader = new PdfReader(INPUTFILE);

    int n = reader.getNumberOfPages();
    PdfImportedPage page;
    // Traversing through all the pages
    for (int i = 1; i <= n; i++) {
            page = writer.getImportedPage(reader, i);
            Image instance = Image.getInstance(page);
            //Save a specific page threshold for displaying in a scroll view inside your App
    }
    document.close();
}

You can also use this link as a reference:
Reading a pdf file using iText library
I hope this helps.

于 2013-10-03T05:21:32.923 回答