Пример #1
0
        private void RenderPdfDocument(PdfDocument pdfDocument, bool preRender, PageSizeInfo pageSizeInfo, bool includeBackgroundObjects, bool portrait)
        {
            if (_preRendered && preRender)
            {
                throw new InvalidOperationException("Prerender has already been performed.");
            }

            var doc = GetDocument(preRender, portrait);

            var docRenderer = new DocumentRenderer(doc);

            docRenderer.PrepareDocument();

            for (var ii = 0; ii < doc.Sections.Count; ii++)
            {
                var page = AddPage(pdfDocument, pageSizeInfo, portrait);

                var gfx = _graphicsFactory.PrepareGraphics(page, docRenderer, ii);

                DoRenderStuff(gfx, new XRect(0, 0, page.Width, page.Height), preRender, ii, _template.SectionList.Sum(x => x.GetRenderPageCount()), includeBackgroundObjects, new XRect(0, 0, 0, 0));
            }

            if (preRender)
            {
                _preRendered = true;
            }
        }
Пример #2
0
 internal Renderer(IGraphicsFactory graphicsFactory, Template template, DocumentData documentData = null, DocumentProperties documentProperties = null, PageSizeInfo pageSizeInfo = null, bool debug = false, PrinterInteractionMode printerInteractionMode = PrinterInteractionMode.None)
 {
     _template               = template;
     _documentData           = documentData;
     _documentProperties     = documentProperties;
     _printerInteractionMode = printerInteractionMode;
     _pageSizeInfo           = pageSizeInfo ?? new PageSizeInfo(PageSize.A4);
     if (debug)
     {
         _debugData = new DebugData();
     }
     _graphicsFactory = graphicsFactory;
 }
Пример #3
0
 private void PreRender(PageSizeInfo pageSizeInfo, bool includeBackgroundObjects, bool portrait)
 {
     //TODO: If prerender with one format (pageSize) and printing with another.
     //or, if template or document data changed between render and pre-render then things will be messed up.
     if (!_preRendered)
     {
         var hasMultiPageElements = _template.SectionList.Any(x => x.Pane.ElementList.Any(y => y is MultiPageAreaElement || y is MultiPageElement) || x.Header.ElementList.Any(y => y is MultiPageAreaElement || y is MultiPageElement) || x.Footer.ElementList.Any(y => y is MultiPageAreaElement || y is MultiPageElement));
         if (hasMultiPageElements)
         {
             var pdfDocument = CreatePdfDocument();
             RenderPdfDocument(pdfDocument, true, pageSizeInfo, includeBackgroundObjects, portrait);
         }
     }
 }
Пример #4
0
        private static PdfPage AddPage(PdfDocument pdfDocument, PageSizeInfo pageSizeInfo, bool portrait)
        {
            var page = pdfDocument.AddPage();

            if (pageSizeInfo.IsCustomSize)
            {
                page.Width  = pageSizeInfo.Width;
                page.Height = pageSizeInfo.Height;
            }
            else
            {
                page.Size = pageSizeInfo.PageSize;
            }

            if (!portrait)
            {
                page.Rotate = 270;
            }

            return(page);
        }
Пример #5
0
        private PageSizeInfo GetPageSizeInfo(PrinterSettings printerSettings)
        {
            PageSizeInfo pageSizeInfo;

            switch (_printerInteractionMode)
            {
            case PrinterInteractionMode.None:
                pageSizeInfo = new PageSizeInfo(_pageSizeInfo.PageSize);
                break;

            case PrinterInteractionMode.Active:
                try
                {
                    var paperKind = printerSettings.DefaultPageSettings.PaperSize.Kind;
                    if (paperKind.ToString() == "Custom")
                    {
                        pageSizeInfo = GetDefaultPageSizeInfo(printerSettings);
                    }
                    else
                    {
                        pageSizeInfo = new PageSizeInfo(paperKind.ToString());
                    }
                }
                catch (ArgumentException)
                {
                    pageSizeInfo = GetDefaultPageSizeInfo(printerSettings);
                }
                break;

            default:
                throw new ArgumentOutOfRangeException(string.Format("Unknown printer interaction mode {0}.", _printerInteractionMode));
            }


            return(pageSizeInfo);
        }
Пример #6
0
 public Renderer(Template template, DocumentData documentData = null, DocumentProperties documentProperties = null, PageSizeInfo pageSizeInfo = null, bool debug = false, PrinterInteractionMode printerInteractionMode = PrinterInteractionMode.None)
     : this(new MyGraphicsFactory(), template, documentData, documentProperties, pageSizeInfo, debug, printerInteractionMode)
 {
 }