Read or open a PDF file using iText in android

泄露秘密 提交于 2020-01-02 05:44:30

问题


i am new to android application development. using iText i had done the PDF creation n write on that created file now i want to read that PDF file. how to open or read a PDF file using iText.

Examples will be appreciable..

thenx in advance.....!!!

which is the best library to render the PDF file..???? JPedal / iText / gnujpdf or anyother.....?????


回答1:


Actually, iText is only for PDF creation, it doesn't contains viewer part. So, you need to choose some another library. You can follow the link provided by Azharahmed to find some useful libraries.




回答2:


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.



来源:https://stackoverflow.com/questions/9291734/read-or-open-a-pdf-file-using-itext-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!