Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

reading PDF files in java

807589Sep 11 2008 — edited Sep 12 2008
Hi,

can any one help me on how to read pdf files in java using itext. I have written some piece of code but it is of no use. It is giving some garbage.

import java.io.*;
import java.util.*;
import java.lang.*;

import com.lowagie.text.pdf.PdfReader;

public class PdfAccess
{
public static void main(String[] args)
{
try {
String pdfFile = args[0];
PdfReader reader = new PdfReader(pdfFile);
int pageCount = reader.getNumberOfPages();
System.out.println(pageCount);
String content = " ";

for(int i=1;i<=pageCount;i++) {
byte[] pageContent = reader.getPageContent(i);
content = content+(pageContent.toString());
}
System.out.println(content.trim());
} catch(Exception e) { }

}
}

can any one help me on how to get contents of the file. Are there examples avalilable??
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 10 2008
Added on Sep 11 2008
3 comments
734 views