Thursday, May 24, 2012

Reading a pdf file


Here we are try to read a pdf file with help of iText . You can download the iText binary from http://sourceforge.net/projects/itext/. 
import java.io.FileOutputStream;
import java.io.IOException;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Image;
import com.itextpdf.text.pdf.PdfImportedPage;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfWriter;
public class ReadAndUsePdf {
private static String INPUTFILE = "c:/temp/FirstPdf.pdf";
private static String OUTPUTFILE = "c:/temp/ReadPdf.pdf";
public static void main(String[] args) throws DocumentException,
IOException {
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;
// Go through all pages
for (int i = 1; i <= n; i++) {
// Only page number 2 will be included
if (i == 2) {
page = writer.getImportedPage(reader, i);
Image instance = Image.getInstance(page);
document.add(instance);
}
}
document.close();
}
}

28 comments:

  1. Hi your blog is good but it can be better. No hard feelings! This is just my personal opinion. You have to stand out among millions of online writers who are blogging like crazy, uploading articles every micro-second. There are wonderful tips for freelancers who gain by getting `online noticed’ – in other words `web visible’. Check out how to edit photograph,freelance photographywebsites. They offer the best hints on great blog writing.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. That was a great message in my carrier, and It's wonderful commands like mind relaxes with understand words of knowledge by information's.
    Best Devops Training in pune

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle, so keep on updates.
    Selenium Training in Chennai
    software testing selenium training
    ios developer course in chennai
    Digital Marketing Course in Chennai
    JAVA J2EE Training Institutes in Chennai
    Java training institutes in chennai
    java courses

    ReplyDelete

  7. I am really enjoying reading your well written articles.
    It looks like you spend a lot of effort and time on your blog.
    I have bookmarked it and I am looking forward to reading new articles. Keep up the good work..
    Java Training in Bangalore
    Advanced Java Training Institute in Bangalore
    Best Institute For Java Course in Bangalore
    Java Training Classes in Bangalore
    Java Training Courses in Bangalore

    ReplyDelete
  8. We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.
    iosh course in chennai

    ReplyDelete
  9. This is a good post. This post give truly quality information. I’m definitely going to look into it. Really very useful tips are provided here. thank you so much. Keep up the good works.
    Ethical Hacking Certification 
    Hacking Course 
    Learn Ethical Hacking 
    Python Training in Chennai
    Python course in Chennai
    Python Classes in Chennai

    ReplyDelete
  10. This comment has been removed by the author.

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. This comment has been removed by the author.

    ReplyDelete
  13. This is an awesome post.Really very informative and creative contents. These concept is a good way to enhance the knowledge.I like it and help me to development very well.Thank you for this brief explanation and very nice information.Well, got a good knowledge.


    Java training in Chennai

    Java training in Bangalore

    Java training in Hyderabad

    Java Training in Coimbatore

    Java Online Training

    ReplyDelete
  14. GREAT BLOG FOR BEGINNERS. thank you very much for sharing. very useful content and such a great information.
    AI Training in Bangalore

    AI Course in Bangalore

    ReplyDelete
  15. Infycle Technologies, one of the best software training institutes in Chennai offers excellent Oracle PLSQL training in Chennai for freshers and students, and Tech Professionals of any field. Other demanding courses such as Java, Hadoop, Selenium, Big Data, Android, and iOS Development will also be trained with complete hands-on training. After the completion of training, the students will be sent for placement interviews in the core MNC's. Dial 7504633633 to get more info and a free demo.Excellent Oracle PLSQL Training Chennai | Infycle Technologies

    ReplyDelete