title: DynamicPDF image quality loss
body: <p>We are using a product called <a href="http://www.cete.com/index.csp" rel="nofollow noreferrer">DynamicPDF</a> to generate PDF's on the fly from dynamic data from a database. Their documentation says that their software leaves the image bytes intact and doesn't make any changes. Despite this, we have observed that the images we add seem to have quality loss on the resulting PDF output (at least that's how they look). So my question is what do I need to do with the  DynamicPDF API to ensure that the image quality output is equal or close to what I put in?</p>
  
  <p>We are using Version 5.1.2 Build 13650, below is the code that we use to add the image.</p>
  
  <pre><code>private void plcImageMain_LaidOut(object sender, PlaceHolderLaidOutEventArgs e)
  {
   if (e.LayoutWriter.RecordSets.Current.HasData)
   {
           string productId = e.LayoutWriter.RecordSets.Current["ProductId"].ToString();
           string imgUrl = base.SetImageUrlParams(e.LayoutWriter.RecordSets.Current["ImageUrl"] as string, e.ContentArea.Width, e.ContentArea.Height);
  
           System.Drawing.Bitmap bm = base.GetBitmap(imgUrl);
  
           ceTe.DynamicPDF.PageElements.Image img = new ceTe.DynamicPDF.PageElements.Image(bm, 0, 0);
           img.Height = e.ContentArea.Height;
           img.Width = e.ContentArea.Width;
           e.ContentArea.Add(img);
   }
  }
  
  /// &lt;summary&gt;
  /// Gets a bitmap from the requested image url
  /// &lt;/summary&gt;
  /// &lt;param name="imgCtrl"&gt;&lt;/param&gt;
  /// &lt;param name="imgUrl"&gt;&lt;/param&gt;
  protected System.Drawing.Bitmap GetBitmap(string imgUrl)
  {
   // TODO: Add some validation to ensure the url is an image.
   System.Net.WebRequest httpRequest = System.Net.HttpWebRequest.Create(imgUrl);
  
   using (System.Net.HttpWebResponse httpResponse = httpRequest.GetResponse() as System.Net.HttpWebResponse)
   using (Stream imgStream = httpResponse.GetResponseStream())
   {
      System.Drawing.Bitmap bm = System.Drawing.Bitmap.FromStream(imgStream) as System.Drawing.Bitmap;
      return bm;
   }
  }
  </code></pre>
  
  <p><strong>[Edit]</strong></p>
  
  <p><a href="http://www.screencast.com/users/jfedor/folders/Jing/media/6da4b1ad-1d67-463e-a82a-e44e30a9bbd3" rel="nofollow noreferrer">Here</a> is the before and after screenshot.</p>
  
  <p><strong>[Edit]</strong> </p>
  
  <p>Code using GetImage (why so slow?)</p>
  
  <pre><code>protected ceTe.DynamicPDF.Imaging.ImageData GetImageData(string imgUrl)
  {
     ImageData imgData = null;
     using (System.Net.WebClient wc = new System.Net.WebClient())
     {
       imgData = ImageData.GetImage(wc.DownloadData(imgUrl));
     }
    return imgData;
  }
  
  GetImageData ("http://s7d2.scene7.com/is/image/SwissArmy/cm_vm_53900E--111mm_sol_front_a?fmt=jpeg&amp;wid=400&amp;hei=640");
  </code></pre>