4

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.....?????

Wolverine
  • 481
  • 2
  • 10
  • 23
  • 1
    http://stackoverflow.com/questions/3831019/how-to-read-a-pdf-in-android – Samir Mangroliya Feb 15 '12 at 10:40
  • @Samir in that answer it is necessary that we must have a PDFviewer or PDFreader application already installed on device... – Wolverine Feb 15 '12 at 10:42
  • Refer this [link](http://stackoverflow.com/questions/8427052/pdf-reader-in-android) for the rendering the PDF file read out this answer you'll get to know.. http://stackoverflow.com/questions/2883355/how-to-render-pdf-in-android – SilentKiller Feb 15 '12 at 11:01

2 Answers2

7

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.

OleGG
  • 8,589
  • 1
  • 28
  • 34
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.

Community
  • 1
  • 1
Salman Khakwani
  • 6,684
  • 7
  • 33
  • 58