title: pdf created using iTextsharp is fuzzy or blurry
body: <p>I'm creating an image from silverlight grid. Converted into png and inserting it into the pdf using iTextsharp. The end result has a very fuzzy/blurry pdf. If i save the same image as png, it is very clear. How can the result be improved with pdf having a sharper image?</p>
  
  <p>Following is the code snippet (At Silverlight end):</p>
  
  <p>private void GeneratePDF()
  {</p>
  
  <pre><code>SaveFileDialog fsd = new SaveFileDialog();
  fsd.DefaultFileName = "Report.pdf";
  fsd.Filter = "PDF (*.pdf)|*.pdf|*PNG (*.png)|*.png";
  bool? dialogResult = fsd.ShowDialog(); //fsd.ShowDialog();
  if (dialogResult == true)
  {
      BusyWindow.IsBusy = true;
      WriteableBitmap wBitmap = new WriteableBitmap(PreviewWindow.LayoutRoot, null);
  
      int hgt = wBitmap.PixelHeight;
      int wdth = wBitmap.PixelWidth;
  
      EditableImage ei = new EditableImage(wdth, hgt);
  
      for (int y = 0; y &lt; hgt; y++)
      {
          for (int x = 0; x &lt; wdth; x++)
          {
              int pixel = wBitmap.Pixels[((y * wdth) + x)];
              ei.SetPixel(x, y, (byte)((pixel &gt;&gt; 16) &amp; 0xff), (byte)((pixel &gt;&gt; 8) &amp; 0xff), (byte)(pixel &amp; 0xff), (byte)((pixel &gt;&gt; 24) &amp; 0xff));
          }
      }
  
      System.IO.Stream pngStream = ei.GetStream();
  
      printBuffer = new Byte[pngStream.Length];
      pngStream.Read(printBuffer, 0, printBuffer.Length);
  
      switch (fsd.FilterIndex)
      {
          case 1:
              HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create(new Uri(Application.Current.Host.Source.ToString().Substring(0, Application.Current.Host.Source.ToString().LastIndexOf("/")) + "/Png2Pdf.ashx"));
              hwr.Method = "POST";
  
              printStream = fsd.OpenFile();
              printSyncContext = System.Threading.SynchronizationContext.Current;
              hwr.BeginGetRequestStream(new AsyncCallback(PrintStart), hwr);
  
              break;
          case 2:
              //Save the PNG to local disk
              lc.Show();
              System.IO.Stream fs = fsd.OpenFile();
              fs.Write(printBuffer, 0, printBuffer.Length);
              fs.Close();
              BusyWindow.IsBusy = false;
              lc.Close();
              break;
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <p>At Handler:</p>
  
  <pre><code> public void ProcessRequest(HttpContext context)
      {
          int PDFPageHeight = 1056;
          int PDFPageWidth = 814;
  
          if (context.Request.ContentLength &gt; 0)
          {
              System.IO.Stream incomingStream = context.Request.InputStream;  //Get the incoming stream
              System.Drawing.Image img = System.Drawing.Image.FromStream(incomingStream); //Create and image from the stream
  
              int pageHeight = img.Height + (_Margin * 2);
              int pageWidth = img.Width + (_Margin * 2);
  
              iTextSharp.text.Image pdfImage = iTextSharp.text.Image.GetInstance(img, System.Drawing.Imaging.ImageFormat.Png);
              System.IO.MemoryStream pdfStream = new System.IO.MemoryStream();
              iTextSharp.text.Document pdfDoc = new iTextSharp.text.Document(new iTextSharp.text.Rectangle(PDFPageWidth, PDFPageHeight), 0, 0, 0, 0);
  
              iTextSharp.text.pdf.PdfWriter pdfWriter = iTextSharp.text.pdf.PdfWriter.GetInstance(pdfDoc, pdfStream);
  
              pdfWriter.CloseStream = false;
  
              pdfDoc.Open();
  
              Bitmap bmp = new Bitmap(incomingStream);
              int pages = (int)Math.Floor((decimal)(bmp.Height / PDFPageHeight));
  
              for (int i = 0; i &lt; pages; i++)
              {
                  pdfDoc.NewPage();
  
                  Rectangle PageRect = new Rectangle(0, (PDFPageHeight * i), img.Width, PDFPageHeight);
  
                  Bitmap pageBMP = bmp.Clone(PageRect, System.Drawing.Imaging.PixelFormat.DontCare);
                  Image pageImage = (Image)pageBMP;
                  pdfDoc.Add(iTextSharp.text.Image.GetInstance(pageImage, System.Drawing.Imaging.ImageFormat.Png));
              }
  
              pdfDoc.Close();
  
              context.Response.Clear();
              context.Response.ContentType = "application/pdf";
              context.Response.AppendHeader("Content-Disposition", "attachment; filename=Export.pdf");
              context.Response.AppendHeader("Content-Length", pdfStream.Length.ToString());
              context.Response.Buffer = false;
  
              if (pdfStream.Position &gt; 0) { pdfStream.Position = 0; };
  
              Byte[] bytesRead = new Byte[_BufferSize];
  
              long toRead = pdfStream.Length;
  
              while (toRead &gt; 0 &amp;&amp; context.Response.IsClientConnected)
              {
                  if (_BufferSize &gt; toRead)
                  {
                      _BufferSize = (int)toRead;
                      bytesRead = new Byte[_BufferSize];
                  };
  
                  pdfStream.Read(bytesRead, 0, _BufferSize);
  
                  context.Response.OutputStream.Write(bytesRead, 0, _BufferSize);
  
                  context.Response.Flush();
  
                  bytesRead = new Byte[_BufferSize];
  
                  toRead -= _BufferSize;
              }
  
              context.Response.OutputStream.Flush();
              context.Response.End();
  
              if (pdfStream != null)
              {
                  pdfStream.Close();
                  pdfStream.Dispose();
              }
          }
      }
  </code></pre>