Hey howzit,
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.
// step 1: creation of a document-object
iTextSharp.text.
Document document = new iTextSharp.text.Document(iTextSharp.text.PageSize.A4, 50, 50, 50, 50); // step 2: // we create a writer that listens to the documentiTextSharp.text.pdf.
PdfWriter writer = iTextSharp.text.pdf.PdfWriter.GetInstance(document, new FileStream("dout.pdf", FileMode.Create)); // step 3: we Open the documentdocument.Open();
// step 4: we Add some contentdocument.Add(
new Annotation("annotation", "This annotation is placed on an position", 100f, 500f, 200f, 600f)); // step 5: we close the documentdocument.Close();

How do I add annotations to an existing PDF file?
devgrp
Here is my test code:
using System;
using System.IO;
using iTextSharp.text;
using iTextSharp.text.pdf;
namespace PDFTest
{
class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
Document doc = new Document( PageSize.A4, 50, 50, 50, 50 );
PdfWriter writer = PdfWriter.GetInstance( doc, new FileStream("test.pfd", FileMode.OpenOrCreate) );
doc.AddDocListener( writer );
doc.Open();
doc.Add( new Annotation("annotation", "This annotation is placed on an position.", 100f, 500f, 200f, 600f) );
doc.Close();
Console.WriterLine("Finished...");
Console.ReadLine();
}
}
}
_jesse
AL-Wakeel Adnan
The D
KZoli
You say you want to add annotaions to an existing PDF but you create a FileStream with the FileMode flag set to Create. This will truncate the existing file when it exists. So you loose all you existing data. Try to specify the FileMode flag with Open.
Alan Grosz
http://prdownloads.sourceforge.net/itextsharp/iTextSharp.tutorial.01.zip download
Open the project and go to Chap0303.cs, this is where you will find the code that I am using. The .dll file is in the debug folder
Keith714
Hey, aparently you can use the pdfstamper class which you find on this site: http://itextdocs.lowagie.com/tutorial/general/copystamp/#pdfwriter
But it seems to be the java version of the itext, because iTextSharp is a java ported lib. Perhaps you could have a look at it and figure out how to use it in C#