Thursday, April 29, 2010

How to extract comments from pdf using Itext

Hi Friends,

Here is the code of extracting comments from the PDF file using the itext.This extracts the comments of each page one by one and print them on the console.

package pdftest;
import com.itextpdf.text.pdf.PdfArray;
import com.itextpdf.text.pdf.PdfDictionary;
import com.itextpdf.text.pdf.PdfName;
import com.itextpdf.text.pdf.PdfObject;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.PdfString;
import java.util.ListIterator;

public class CommentsTest {

public static void main(String args[]) {
try {
System.out.println("Hi in the Comments Test");
PdfReader reader = new PdfReader("c:\\temp\\testattachments.pdf");

for (int i = 1; i <= reader.getNumberOfPages(); i++)

PdfDictionary page = reader.getPageN(i);
PdfArray annotsArray = null;


annotsArray = page.getAsArray(PdfName.ANNOTS);
for (ListIterator iter = annotsArray.listIterator(); iter.hasNext();)
PdfDictionary annot = (PdfDictionary) PdfReader.getPdfObject(;
PdfString content = (PdfString) PdfReader.getPdfObject(annot.get(PdfName.CONTENTS));
if (content != null) {

} catch (Exception e) {



Vajahat Ali


Ben said...

You are wonderful. Thank you.

Anonymous said...

I can not claim complete originality for all things in this study. [url=][/url You may do something once a day, once a week, once a month. [url=]canada goose women parka[/url] Llgvxudsb
[url=]pandora store[/url] Nrsnuoaxo [url=]canada goose outlet[/url] lozdlgwri

Anonymous said...

But for many developers, all of this came to a halt this week when Roku removed 25 channels with foreign-language content, effectively shutting down the entire international section of its channel store.. Reggie acknowledges that they trying to get more units into stores as fast as possible while still trying to make the Wii U sound like an item so popular that it is flying off shelves.. It those so-called regular users that are the key tothis deal, all those folks that have never played a Zynga game before, or any mobile game for that matter. He said a PR person should look presentable they should represent the company. ghd online Radical fats want to tear up the rulebook and spit on everything they been told about clothes.

Anonymous said...

What i do not realize is if truth be told how
you're no longer really much more neatly-liked than you may be right now. You are so intelligent. You already know thus significantly in the case of this topic, produced me in my view consider it from so many numerous angles. Its like women and men aren't interested unless it is one thing
to do with Girl gaga! Your own stuffs outstanding.
All the time handle it up!

Here is my web site; online graduate certificates

lee woo said...

Smile, smile, smile at your mind as often as possible. Your smiling will considerably reduce your mind's tearing tension. See the link below for more info.


Silvia Jacinto said...

I really love your blog there's a lot to share. Keep it up.Visit my site too.

Jorge Frew said...

It's best to participate in a contest for top-of-the-line blogs on the web. I'll advocate this site! casino play