3

I want to read a pdf file using Java/Android from my SD card. I imported the itextpdf5.1.1.jar file in to Eclipse. I am able to read a file if I create a new file from an existing one, like this:

public void readPdfFile(String pFilename){

    try{
        Document document = null;
        document = new Document();
    PdfWriter writer = PdfWriter.getInstance(document,
            new FileOutputStream(OUTPUTFILE));
    document.open();
    PdfReader reader = new PdfReader(pFilename);
    int n = reader.getNumberOfPages();
    PdfImportedPage page;
    // Go through all pages
    for (int i = 1; i <= n; i++) {
        // Only page number 2 will be included
        if (i == 1) {
            page = writer.getImportedPage(reader, i);
            Image instance = Image.getInstance(page);
            document.add(instance);
        }
    }
    }

    catch (DocumentException e) {
        // TODO: handle exception
        System.out.println("Doc Exception"+ e);
    }
    catch (IOException io) {
        // TODO: handle exception
        System.out.println("IO Exception"+ io);
    }
}

But I want to read the file without creating a new pdf file in my sd card. How can I do this?

Please guide me how to create a pdf reader application in Android that reads the pdf file and also allows you to enter a page number to jump to.

Tripaty Sahu
  • 955
  • 4
  • 13
  • 32

2 Answers2

0

It is impossible to replace an existing PDF. We can able to write or manipulate anything in our PDF but it could not be replaced with the original. While using iText we can make change and save it in a new file and not in a original file, this information is available in the iText official website.

BobDroid
  • 1,898
  • 5
  • 19
  • 39
-1

You can use awt tools like jPanel in java with iText to read a pdf file.

In Android there is a pdf viewer for reading or viewing pdf files.