The Document object in iText and iTextSharp is an abstraction that automatically handles various distances, spacers, and fields. Unfortunately for you, this also means that when you call doc.Add() it takes into account the existing fields of the document. (Also, if you add anything else, an image will be added regarding this.)
One solution would be to simply remove the fields:
doc.SetMargins(0, 0, 0, 0);
Instead, itβs easier to add the image directly to the PdfWriter object that you get from calling PdfWriter.GetInstance() . You are currently discarding and not saving this object, but you can easily change your line:
PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(saveFileDialog1.FileName,FileMode.Create));
Then you can access the DirectContent property for PdfWriter and call its AddImage() method:
writer.DirectContent.AddImage(img);
Before doing this, you must also fully position the image by calling:
img.SetAbsolutePosition(0, 0);
The following is a complete working C # 2010 WinForms application focused on iTextSharp 5.1.1.0, which shows the DirectContent method above. It dynamically creates two images of different sizes with two red arrows stretching both vertically and horizontally. Obviously, your code will simply use standard image loading and thus may skip this, but I would like to give a complete working example. See the notes in the code for more details.
using System; using System.Drawing; using System.Windows.Forms; using System.IO; using iTextSharp.text; using iTextSharp.text.pdf; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) {