title: wpf c# get printer's available papersize names - like PrinterSettings.PaperSize.PaperName in WinForm
body: <p>I moved from WinForms to WPF. In my old WinForms application to get the names of the PaperSizes works brilliant (<strong><em>PrinterSettings.PaperSize.PaperName</em></strong>). How can i get the list of those papersizes in WPF?</p>
  
  <p>Please note that in WPF <strong><em>PrintCapabilities.PageMediaSizeCapability.PageMediaSizeName</em></strong> is a completely different thing (and give bad results in my case). I mean when the user can create unique paper size(s) in their printer's driver preferences and they can add a name for it (like "<em>John's poster huge</em>"). And i would like to get that name list. What i mentioned, in WinForms it works perfectly. In WPF, the <strong><em>PageMediaSize</em></strong> can't see these names.</p>
  
  <p>If there is any solution for it i would also like to know how to change the the printer's paper size to the choosen one.</p>
  
  <p>Here is the old WinForms version of how i get the papersizes. This one needs to translate to WPF....</p>
  
  <pre><code>public partial class Form1 : Form
  {
      public PrintDocument printDoc;
      public string[] PrinterList;
      public string[] PaperSizeList;
      public PaperSize[] pkPaperSizeList; 
  
      public Form1()
      {
          InitializeComponent();
  
          printDoc = new PrintDocument();
          PrinterList = new string[PrinterSettings.InstalledPrinters.Count];
  
          GetPrinterNames();
          GetPaperSizes();
      }
      public void GetPrinterNames()
      {
          for (int i = 0; i &lt; PrinterSettings.InstalledPrinters.Count; i++)
          {
              PrinterList[i] = PrinterSettings.InstalledPrinters[i];
              comboBox_printerList.Items.Add(PrinterList[i]);
          }
          comboBox_printerList.SelectedIndex = 0;
          printDoc.PrinterSettings.PrinterName = PrinterList[0];
      }
      public void GetPaperSizes()
      {
          int j = 0;
          comboBox_paperList.Items.Clear();
          PaperSizeList = new string[printDoc.PrinterSettings.PaperSizes.Count];
          pkPaperSizeList = new PaperSize[printDoc.PrinterSettings.PaperSizes.Count];
  
          foreach (PaperSize paperSize in printDoc.PrinterSettings.PaperSizes)
          {
              PaperSizeList[j] = paperSize.PaperName;
              pkPaperSizeList[j] = paperSize;
              comboBox_paperList.Items.Add(PaperSizeList[j]);
              j++;
          }
          comboBox_paperList.SelectedIndex = 0;
      }
  
      private void comboBox_printerList_SelectedIndexChanged(object sender, EventArgs e)
      {
          printDoc.PrinterSettings.PrinterName = PrinterList[comboBox_printerList.SelectedIndex];
          GetPaperSizes();
      }
  
      private void comboBox_paperList_SelectedIndexChanged(object sender, EventArgs e)
      {
          printDoc.DefaultPageSettings.PaperSize = pkPaperSizeList[comboBox_paperList.SelectedIndex];
      }
  }
  </code></pre>