title: How to get FixedDocument from PageDocuments
body: <p>I am working with printing in WPF.<br/>
  I implement a class which inherit from <code>DocumentPaginator</code> class</p>
  
  <pre><code>public class ReportPaginator : DocumentPaginator
  {
      private double pageUpperLimit;
  
      private double pageDownLimit;
  
      private Model.Report printedReport;
  
      private int pageCount;
  
      public override IDocumentPaginatorSource Source
      {
          get
          {
              return null;
          }
      }
  
      public override bool IsPageCountValid
      {
          get { return true; }
      }
  
      public override int PageCount
      {
          get { return pageCount; }
      }
  
      public override Size PageSize
      {
          get
          {
              return new Size(printedReport.PageSize.Width, printedReport.PageSize.Height);
          }
          set
          {
              // validate the value.
              if (value != null)
              {
                  throw new ArgumentException("page size can not be null");
              }
  
              // TODO: here we have to validate if the page is A3, A4, A5. this is to set the SizeName.
              // if you did not set the sizeName here we will get an exception.
              printedReport.PageSize = new Model.PageSize { Height = value.Height, Width = value.Width };
              CalculatesPage();
              // if we have to set the PageSize (I do not think so), do not forget to call the PaginateData method.
          }
      }
  
      public ReportPaginator( Model.Report report)
      {
          printedReport = report;
          CalculatesPage();
      }
  
      public override DocumentPage GetPage(int pageNumber)
      {
          // validate the argument.
          if (pageNumber &lt; 0)
          {
              throw new ArgumentException("pageNumber parameter could not be negative number", "pageNumber");
          }
  
          // if the argument is outside of the available pages, return 
          if (pageNumber &gt; pageCount - 1)
          {
              return DocumentPage.Missing;
          }
  
          // specify the start pixel and end pixel of the page according to the height of the report.
          pageUpperLimit = pageNumber * PageSize.Height;
          pageDownLimit = (pageNumber + 1) * PageSize.Height;
  
          // create DrawingVisual for this DocumentPage
          DrawingVisual visual = new DrawingVisual();
  
          // get the DrawingContext for this DrawingVisual for this page.
          using (DrawingContext pageContext = visual.RenderOpen())
          {
              // drawing operations for elements and sections go here.
  
              // we will use the for loop instead of the foreach loop to enumerate the sections
              // because we will need the know in which section we draw.
              for (int sectionIndex = 0; sectionIndex &lt; printedReport.Sections.Count; sectionIndex++)
              {
                  PrintSection(pageContext, sectionIndex);
  
                  foreach (Model.BaseReportControl control in printedReport.Sections[sectionIndex].Controls)
                  {
                      PrintControl(pageContext, sectionIndex, control);
                  }
              }
          }  // close the DrawingContext.
  
          return new DocumentPage(visual);
      }
  }
  </code></pre>
  
  <p>there is more helper methods to do the jobs.</p>
  
  <p>I want to create <code>FixedDocument</code> object to return it from the <code>Source</code> property
  using <code>DocumentPage</code> object that returned from <code>GetPage</code> Method.</p>
  
  <p>I need a <code>FixedDocument</code> to be returned from the source Property
  Because I want to make a preview to the File before printing</p>
  
  <pre><code>ReportPreviewerWindow window = new ReportPreviewerWindow();
  window.previewer.Document = new ReportPaginator(printedSurface.ModelReport).Source;
  window.ShowDialog();
  </code></pre>
  
  <p>the previewer is <code>DocumentViewer</code> Object exists in the <code>ReportPreviewerWindow</code></p>
  
  <pre><code>&lt;Window x:Class="TanmiaGrp.Report.Designer.ReportPreviewerWindow"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
      Title="Report Previewer" &gt;
     &lt;Grid&gt;
        &lt;DocumentViewer x:Name="previewer"/&gt;
     &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>