title: How to let C# save a WPF canvas to an image in a PDF document at A1 size?
body: <p>I am in trouble, because I have to save a canvas to an image in a PDF document at A1 size with C#. </p>
  
  <p>I have tried a few examples at the internet, but they do not work for me.</p>
  
  <p>I already have done a little part of this requirement. With this code, I can export it as an image:</p>
  
  <pre><code>public static class util { 
      public static void SaveWindow(Window window, int dpi, string filename)
      {
          var rtb = new RenderTargetBitmap(
              (int)window.Width, //width
              (int)window.Width, //height
              dpi, //dpi x
              dpi, //dpi y
              PixelFormats.Pbgra32 // pixelformat
              );
          rtb.Render(window);
  
          SaveRTBAsPNG(rtb, filename);
  
      }
  
      public static void SaveCanvas(Window window, Canvas canvas, int dpi, string filename)
      {
          Size size = new Size(window.Width, window.Height);
          canvas.Measure(size);
          //canvas.Arrange(new Rect(size));
  
          var rtb = new RenderTargetBitmap(
              (int)window.Width, //width
              (int)window.Height, //height
              dpi, //dpi x
              dpi, //dpi y
              PixelFormats.Pbgra32 // pixelformat
              );
          rtb.Render(canvas);
  
          SaveRTBAsPNG(rtb, filename);
      }
  
      private static void SaveRTBAsPNG(RenderTargetBitmap bmp, string filename)
      {
          var enc = new System.Windows.Media.Imaging.PngBitmapEncoder();
          enc.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(bmp));
  
          using (var stm = System.IO.File.Create(filename))
          {
              enc.Save(stm);
          }
      }
  </code></pre>
  
  <p>Code above saves the canvas as an image.</p>