Print PDF or Image using PrintDocument
<p>I wrote code to print GIF image using print document and it works fine but facing problem for its height and width related.</p>

<p>My code:</p>

<pre><code>PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(this.PrintPage);
pd.Print();

private void PrintPage(object sender, PrintPageEventArgs ev)
      {         
            FileStream fs = File.Open(@"D:\\Test2.gif", FileMode.Open, FileAccess.Read);
            var image = System.Drawing.Image.FromStream(fs);
            try
            {
                ev.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
                ev.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                ev.Graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
                ev.Graphics.CompositingMode = System.Drawing.Drawing2D.CompositingMode.SourceCopy;
                ev.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

                double WidthRatio = ev.MarginBounds.Width / (double)image.Width;
                double HeightRatio = ev.MarginBounds.Height / (double)image.Height;
                if (WidthRatio &gt; HeightRatio)
                {
                    ev.Graphics.DrawImage(image, 0, 0, Convert.ToInt32(HeightRatio * ev.MarginBounds.Width), ev.MarginBounds.Height);
                }
                else
                {
                    ev.Graphics.DrawImage(image, 0, 0, ev.MarginBounds.Width, Convert.ToInt32(WidthRatio * ev.MarginBounds.Height));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                fs.Close();
                image.Dispose();
            }
        }
</code></pre>

<p>Image properly opened But facing problem in height width and not properly displayed.
Also want to print pdf using print document.</p>

<p>Please help.</p>
