Content of ITextTest.java
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();
}
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.