If I have an existing PDF that has a graphic on it, and I simple want a user to be able to click a point on the pdf, and drop a letter at the point the click, like A... B... etc. I'm thinking that ITextSharp could handle something like this, but frankly, I'm not sure how to accomplish it. Can you offer some guidance?
Wouldn't you probably want to load the PDF, turn it into something that you can render in your app (ie, some editable document object), make changes, and then write it back out to PDF?
Granted, that's probably a lot of work for what you are trying to accomplish, but most PDF tools I am aware of don't actually edit the .PDF directly.
iTextSharp may have the ability to load .PDF files into some sort of document tree that you can then manipulate. I would start by seeing if it does such a thing, and then try to change some of the nodes, or perhaps add nodes corresponding to your annotations.
It may not be possible to see your changes reflected in real time, so you probably will want to "fake" the changes by layering them over your render of the .PDF file as simple lable objects. That's probably the easiest way to start.
You can certainly use ITextSharp to add content to an existing PDF. There are samples on the web that can show you how. (It's been a while since I've done this, and my needs were to add watermark images to existing PDFs.)
ITextSharp doesn't read PDFs well, so you'll probably want to find something else to display the PDF. You may need to overlay a transparent window over whatever displays the PDF so you can catch the click, but that all depends upon the viewer you find.
Bearing in mind that I have only ever used PDFNet SDK for PDF manipulation tasks, I believe everything you are asking about can be achieved with that library, although you may have to deal with some complexity with coordinate conversion from the click to the location in the document, and again to building the matrix that locates the text where you need it on the write.
They do provide a simple WinForms sample PDF viewer application that might serve as a good starting point for your experimentation.
I haven't needed to go this deep into editing, myself. The starting points for documentation are in the FAQ (How to add a watermark to a page) and the knowledge base. The API documentation is also quite extensive and publicly available on the website.
Here's a C# example using the commercial Quick PDF Library.
using System;
using System.IO;
using System.Drawing;
using System.Windows.Forms;
using QuickPDFAX0714;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
private string LicenseKey = " your key here ";
private string OriginalFileName = "D:\\QuickPDFLibrary\\hello1.pdf";
private string NewFileName = "D:\\QuickPDFLibrary\\hello2.pdf";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
ShowPDF(OriginalFileName);
}
private void ShowPDF(string fileName)
{
PDFLibrary qp = new PDFLibrary();
qp.UnlockKey(LicenseKey);
qp.LoadFromFile(fileName);
// Fit width of PDF to width of picture box
int dpi = Convert.ToInt32((pictureBox1.Width * 72) / qp.PageWidth());
byte[] bmpData = (byte[])qp.RenderPageToVariant(dpi, 1, 0);
MemoryStream ms = new MemoryStream(bmpData);
Bitmap bmp = new Bitmap(ms);
pictureBox1.Image = bmp;
ms.Dispose();
}
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
PDFLibrary qp = new PDFLibrary();
qp.UnlockKey(LicenseKey);
qp.LoadFromFile(OriginalFileName);
// Calculate co-ordinates, width of PDF fitted to width of PictureBox
double xpos = ((double)e.X / (double)pictureBox1.Width) * qp.PageWidth();
double ypos = qp.PageHeight() - ((double)e.Y / (double)pictureBox1.Width) * qp.PageWidth();
qp.SetTextSize(24);
qp.SetTextColor(1, 0, 0);
qp.DrawText(xpos, ypos, "A");
qp.SaveToFile(NewFileName);
ShowPDF(NewFileName);
}
}
}