问题
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