/// <summary>
        /// Renders a MigraDoc document to the specified graphics object.
        /// </summary>
        public void RenderPage(XGraphics gfx, int page, PageRenderOptions options)
        {
            if (_formattedDocument.IsEmptyPage(page))
            {
                return;
            }

            FieldInfos fieldInfos = _formattedDocument.GetFieldInfos(page);

            fieldInfos.Date = _printDate != DateTime.MinValue ? _printDate : DateTime.Now;

            if ((options & PageRenderOptions.RenderHeader) == PageRenderOptions.RenderHeader)
            {
                RenderHeader(gfx, page);
            }
            if ((options & PageRenderOptions.RenderFooter) == PageRenderOptions.RenderFooter)
            {
                RenderFooter(gfx, page);
            }

            if ((options & PageRenderOptions.RenderContent) == PageRenderOptions.RenderContent)
            {
                RenderInfo[] renderInfos = _formattedDocument.GetRenderInfos(page);
                //foreach (RenderInfo renderInfo in renderInfos)
                int count = renderInfos.Length;
                for (int idx = 0; idx < count; idx++)
                {
                    RenderInfo renderInfo = renderInfos[idx];
                    Renderer   renderer   = Renderer.Create(gfx, this, renderInfo, fieldInfos);
                    renderer.Render();
                }
            }
        }
        /// <summary>
        /// Renders a MigraDoc document to the specified graphics object.
        /// </summary>
        public void RenderPage(XGraphics gfx, int page, PageRenderOptions options, CancellationToken ct)
        {
            if (this.formattedDocument.IsEmptyPage(page))
            {
                return;
            }

            FieldInfos fieldInfos = this.formattedDocument.GetFieldInfos(page);

            if (this.printDate != DateTime.MinValue)
            {
                fieldInfos.date = this.printDate;
            }
            else
            {
                fieldInfos.date = DateTime.Now;
            }

            if ((options & PageRenderOptions.RenderHeader) == PageRenderOptions.RenderHeader)
            {
                RenderHeader(gfx, page, ct);
            }
            if ((options & PageRenderOptions.RenderFooter) == PageRenderOptions.RenderFooter)
            {
                RenderFooter(gfx, page, ct);
            }

            if ((options & PageRenderOptions.RenderContent) == PageRenderOptions.RenderContent)
            {
                RenderInfo[] renderInfos = this.formattedDocument.GetRenderInfos(page);
                //foreach (RenderInfo renderInfo in renderInfos)
                int count = renderInfos.Length;
                for (int idx = 0; idx < count; idx++)
                {
                    ct.ThrowIfCancellationRequested();
                    RenderInfo renderInfo = renderInfos[idx];
                    Renderer   renderer   = Renderer.Create(gfx, this, renderInfo, fieldInfos);
                    renderer.Render(ct);
                }
            }
        }
Example #3
0
        /// <summary>
        /// Renders a MigraDoc document to the specified graphics object.
        /// </summary>
        public void RenderPage(XGraphics gfx, int page, PageRenderOptions options)
        {
            if (this.formattedDocument.IsEmptyPage(page))
            return;

              FieldInfos fieldInfos = this.formattedDocument.GetFieldInfos(page);

              if (this.printDate != DateTime.MinValue)
            fieldInfos.date = this.printDate;
              else
            fieldInfos.date = DateTime.Now;

              if ((options & PageRenderOptions.RenderHeader) == PageRenderOptions.RenderHeader)
            RenderHeader(gfx, page);
              if ((options & PageRenderOptions.RenderFooter) == PageRenderOptions.RenderFooter)
            RenderFooter(gfx, page);

              if ((options & PageRenderOptions.RenderContent) == PageRenderOptions.RenderContent)
              {
            RenderInfo[] renderInfos = this.formattedDocument.GetRenderInfos(page);
            //foreach (RenderInfo renderInfo in renderInfos)
            int count = renderInfos.Length;
            for (int idx = 0; idx < count; idx++)
            {
              RenderInfo renderInfo = renderInfos[idx];
              Renderer renderer = Renderer.Create(gfx, this, renderInfo, fieldInfos);
              renderer.Render();
            }
              }
        }