How to read a PDF document using IText? - BunksAllowed

BunksAllowed is an effort to facilitate Self Learning process through the provision of quality tutorials.

Community

demo-image

How to read a PDF document using IText?

Share This



Content of ITextTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.t4b.java.itext.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.pdf.PdfReader;
public class ITextTest {
// reading the content of hello.pdf from pdfs directory......
// use absolute path or relative path of the file......
public static final String filename = "pdfs/hello.pdf";
public static void main(String[] args) {
try {
File file = new File(filename);
new ITextTest().readPdf(filename);
} catch (DocumentException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
public void readPdf(String filename) throws DocumentException, IOException {
PdfReader pdfreader = new PdfReader(new FileInputStream(filename));
System.out.println(pdfreader.getPermissions());
System.out.println(pdfreader.getNumberOfPages());
byte[] content = pdfreader.getPageContent(1);
System.out.println(new String(content));
System.out.println();
pdfreader.close();
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Happy Exploring!



Comment Using!!

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.