EDN Admin
Well-known member
<P>Hey howzit,</P>
<P>I have been searching the net for ways to adding annotations (sticky notes) to PDF files programmatically, I have found one library on sourceforge.net called ITextSharp, but it creates a new PDF file (see code below) and then allows one to add annotations, I want to add annotations to an existing PDF file that is already filled with data and text.</P>
<P> </P>
<P> </P><FONT color=#008000 size=2>
<P>// step 1: creation of a document-object</P></FONT><FONT size=2>
<P>iTextSharp.text.</FONT><FONT color=#008080 size=2>Document</FONT><FONT size=2> document = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> iTextSharp.text.</FONT><FONT color=#008080 size=2>Document</FONT><FONT size=2>(iTextSharp.text.</FONT><FONT color=#008080 size=2>PageSize</FONT><FONT size=2>.A4, 50, 50, 50, 50);</P>
<P></P>
<P></FONT><FONT color=#008000 size=2>// step 2:</P></FONT><FONT size=2>
<P></FONT><FONT color=#008000 size=2>// we create a writer that listens to the document</P></FONT><FONT size=2>
<P>iTextSharp.text.pdf.</FONT><FONT color=#008080 size=2>PdfWriter</FONT><FONT size=2> writer = iTextSharp.text.pdf.</FONT><FONT color=#008080 size=2>PdfWriter</FONT><FONT size=2>.GetInstance(document, </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>FileStream</FONT><FONT size=2>(</FONT><FONT color=#800000 size=2>"dout.pdf"</FONT><FONT size=2>, </FONT><FONT color=#008080 size=2>FileMode</FONT><FONT size=2>.Create));</P>
<P></P>
<P></FONT><FONT color=#008000 size=2>// step 3: we Open the document</P></FONT><FONT size=2>
<P>document.Open();</P>
<P></FONT><FONT color=#008000 size=2>// step 4: we Add some content</P></FONT><FONT size=2>
<P></P>
<P>document.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>Annotation</FONT><FONT size=2>(</FONT><FONT color=#800000 size=2>"annotation"</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>"This annotation is placed on an position"</FONT><FONT size=2>, 100f, 500f, 200f, 600f));</P>
<P></P>
<P></P>
<P></FONT><FONT color=#008000 size=2>// step 5: we close the document</P></FONT><FONT size=2>
<P>document.Close();</P></FONT>
<P> </P>
View the full article
<P>I have been searching the net for ways to adding annotations (sticky notes) to PDF files programmatically, I have found one library on sourceforge.net called ITextSharp, but it creates a new PDF file (see code below) and then allows one to add annotations, I want to add annotations to an existing PDF file that is already filled with data and text.</P>
<P> </P>
<P> </P><FONT color=#008000 size=2>
<P>// step 1: creation of a document-object</P></FONT><FONT size=2>
<P>iTextSharp.text.</FONT><FONT color=#008080 size=2>Document</FONT><FONT size=2> document = </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> iTextSharp.text.</FONT><FONT color=#008080 size=2>Document</FONT><FONT size=2>(iTextSharp.text.</FONT><FONT color=#008080 size=2>PageSize</FONT><FONT size=2>.A4, 50, 50, 50, 50);</P>
<P></P>
<P></FONT><FONT color=#008000 size=2>// step 2:</P></FONT><FONT size=2>
<P></FONT><FONT color=#008000 size=2>// we create a writer that listens to the document</P></FONT><FONT size=2>
<P>iTextSharp.text.pdf.</FONT><FONT color=#008080 size=2>PdfWriter</FONT><FONT size=2> writer = iTextSharp.text.pdf.</FONT><FONT color=#008080 size=2>PdfWriter</FONT><FONT size=2>.GetInstance(document, </FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>FileStream</FONT><FONT size=2>(</FONT><FONT color=#800000 size=2>"dout.pdf"</FONT><FONT size=2>, </FONT><FONT color=#008080 size=2>FileMode</FONT><FONT size=2>.Create));</P>
<P></P>
<P></FONT><FONT color=#008000 size=2>// step 3: we Open the document</P></FONT><FONT size=2>
<P>document.Open();</P>
<P></FONT><FONT color=#008000 size=2>// step 4: we Add some content</P></FONT><FONT size=2>
<P></P>
<P>document.Add(</FONT><FONT color=#0000ff size=2>new</FONT><FONT size=2> </FONT><FONT color=#008080 size=2>Annotation</FONT><FONT size=2>(</FONT><FONT color=#800000 size=2>"annotation"</FONT><FONT size=2>, </FONT><FONT color=#800000 size=2>"This annotation is placed on an position"</FONT><FONT size=2>, 100f, 500f, 200f, 600f));</P>
<P></P>
<P></P>
<P></FONT><FONT color=#008000 size=2>// step 5: we close the document</P></FONT><FONT size=2>
<P>document.Close();</P></FONT>
<P> </P>
View the full article