title: How to Set Document Orientation (for All Pages) in MigraDoc Library?
body: <p>I'm using <a href="http://www.pdfsharp.net/" rel="noreferrer">MigraDoc</a> to programatically generate a PDF file with text, images and tables.</p>
  <p>I need to set <code>Document</code> <strong>Orientation</strong> (for all pages) in the document object to <code>Landscape</code>.</p>
  <p>So I tried the following.</p>
  <pre><code>document.DefaultPageSetup.Orientation = Orientation.Landscape;
  </code></pre>
  <p>But I get the following debug assertion error.</p>
  <pre><code>---------------------------
  Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
  ---------------------------
  
  DefaultPageSetup must not be modified
  </code></pre>
  <p>If I click <strong>Ignore</strong>, it goes through and the <code>Orientation</code> is indeed <code>Landscape</code>.</p>
  <p>However, I want to make sure I am doing this the right way.</p>
  <p>So the question is, how do I set the document orientation for all pages in a <code>Document</code> using the MigraDoc library?</p>
  <p>Here's the rest of the code (so it helps you get the context)</p>
  <pre><code>using System.Runtime.Remoting.Messaging;
  using MigraDoc.DocumentObjectModel;
  
  namespace MyNamespace.PdfReports
  {
      class Documents
      {
          public static Document CreateDocument()
          {
              // Create a new MigraDoc document
              Document document = new Document();
              document.Info.Title = &quot;The Title&quot;;
              document.Info.Subject = &quot;The Subject&quot;;
              document.Info.Author = &quot;Shiva&quot;;
              document.DefaultPageSetup.Orientation = Orientation.Landscape;
  </code></pre>
  <p>Many thanks!<br />
  -Shiva</p>
  <h3>UPDATE:</h3>
  <p><strong>SOLUTION:</strong> Here's the working code, based on <a href="https://stackoverflow.com/users/1015447/thomash">Thomas</a>' answer below (for the benefit of others who maybe looking for this solution).</p>
  <pre><code>// Create a new MigraDoc document
  Document document = new Document();
  //...
  //......
  PageSetup pageSetup = document.DefaultPageSetup.Clone();
  // set orientation
  pageSetup.Orientation = Orientation.Landscape;
  // ... set other page setting you want here...
  </code></pre>