/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="report">report document</param>
        /// <param name="data">report data</param>
        /// <exception cref="ArgumentException">Flow document must have a specified page height</exception>
        /// <exception cref="ArgumentException">Flow document must have a specified page width</exception>
        /// <exception cref="ArgumentException">Flow document can have only one report header section</exception>
        /// <exception cref="ArgumentException">Flow document can have only one report footer section</exception>
        public ReportPaginator(ReportDocument report, ReportData data)
        {
            _report = report;
            _data = data;

            _flowDocument = report.CreateFlowDocument();
            _pageSize = new Size(_flowDocument.PageWidth, _flowDocument.PageHeight);

            if (_flowDocument.PageHeight == double.NaN) throw new ArgumentException("Flow document must have a specified page height");
            if (_flowDocument.PageWidth == double.NaN) throw new ArgumentException("Flow document must have a specified page width");

            _dynamicCache = new ReportPaginatorDynamicCache(_flowDocument);
            ArrayList listPageHeaders = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportHeader));
            if (listPageHeaders.Count > 1) throw new ArgumentException("Flow document can have only one report header section");
            if (listPageHeaders.Count == 1) _blockPageHeader = (SectionReportHeader)listPageHeaders[0];
            ArrayList listPageFooters = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportFooter));
            if (listPageFooters.Count > 1) throw new ArgumentException("Flow document can have only one report footer section");
            if (listPageFooters.Count == 1) _blockPageFooter = (SectionReportFooter)listPageFooters[0];

            _paginator = ((IDocumentPaginatorSource)_flowDocument).DocumentPaginator;

            // remove header and footer in our working copy
            Block block = _flowDocument.Blocks.FirstBlock;
            while (block != null)
            {
                Block thisBlock = block;
                block = block.NextBlock;
                if ((thisBlock == _blockPageHeader) || (thisBlock == _blockPageFooter)) _flowDocument.Blocks.Remove(thisBlock);
            }

            // get report context values
            _reportContextValues = _dynamicCache.GetFlowDocumentVisualListByInterface(typeof(IInlineContextValue));

            FillData();
        }
Пример #2
0
        public ReportPaginator(DocumentPaginator documentPaginator)
        {
            _paginator = documentPaginator;
            _reportDefinition = new ReportDefinition();

            _paginator.PageSize = _reportDefinition.ContentSize;
        }
Пример #3
0
		public DocumentPaginatorWrapper(DocumentPaginator paginator, Size pageSize, Size margin)
		{
			m_PageSize = pageSize;
			m_Margin = margin;
			m_Paginator = paginator;
			m_Paginator.PageSize = new Size(m_PageSize.Width - margin.Width * 2, m_PageSize.Height - margin.Height * 2);
			_dateTime = DateTime.Now;
		}
 public DocumentPaginatorWrapper(DocumentPaginator paginator, Size pageSize, Size margin)
 {
     m_PageSize = pageSize;
     m_Margin = margin;
     m_Paginator = paginator;
     m_Paginator.PageSize = new Size(PageSize.Width - margin.Width * 2,
                                     PageSize.Height - margin.Height * 2);
     m_Typeface = new Typeface("Times New Roman");
 }
Пример #5
0
        public PageRangeDocumentPaginator(
          DocumentPaginator paginator,
          PageRange pageRange)
        {
            _startIndex = pageRange.PageFrom - 1;
            _endIndex = pageRange.PageTo - 1;
            _paginator = paginator;

            // Adjust the _endIndex
            _endIndex = Math.Min(_endIndex, _paginator.PageCount - 1);
        }
Пример #6
0
        public CustomDocumentPaginator(DocumentPaginator paginator, Size pageSize, Size margin, String headerText)
        {
            m_PageSize  = pageSize;
            m_Margin    = margin;
            m_Paginator = paginator;

            m_Paginator.PageSize = new Size(m_PageSize.Width  - margin.Width  * 2,
                                            m_PageSize.Height - margin.Height * 2);

            HeaderText = headerText;
        }
        public PrintingPaginator(DocumentPaginator originalPaginator, Size pageSize, Size pageMargin)
        {
            this._originalPaginator = originalPaginator;
            this._pageSize = pageSize;
            this._pageMargin = pageMargin;

            _originalPaginator.PageSize = new Size(
                _pageSize.Width - _pageMargin.Width * 2,
                _pageSize.Height - _pageMargin.Height * 2);
            _originalPaginator.ComputePageCount();
        }
Пример #8
0
        //------------------------------------------------------------------- 
        // 
        //  Constructors
        // 
        //-------------------------------------------------------------------

        #region Constructors
 
        /// <summary>
        /// Standard constructor. 
        /// </summary> 
        public DocumentGridPage(DocumentPaginator paginator) : base()
        { 
            _paginator = paginator;

            //Attach the GetPageCompleted event handler to the paginator so we can
            //use it to keep track of whether our page has been loaded yet. 
            _paginator.GetPageCompleted += new GetPageCompletedEventHandler(OnGetPageCompleted);
 
            //Set up the static elements of our Visual Tree. 
            Init();
        } 
        private XpsDocument LoadAsXPS(DocumentPaginator paginator)
        {
            var stream = new MemoryStream();
            var docPackage = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite);

            var uri = new Uri(@"memorystream://myXps.xps");
            PackageStore.RemovePackage(uri);
            PackageStore.AddPackage(uri, docPackage);
            var xpsDoc = new XpsDocument(docPackage) { Uri = uri };

            XpsDocument.CreateXpsDocumentWriter(xpsDoc).Write(paginator);

            return xpsDoc;
        }
        /// <summary>
        /// Class constructor
        /// </summary>
        /// <param name="paginator"></param>
        /// <param name="pageSettings"></param>
        /// <param name="printTicket"></param>
        /// <param name="headerFooterfontFamily"></param>
        public DocumentPaginatorWrapper(DocumentPaginator paginator, PageSettings pageSettings, PrintTicket printTicket, FontFamily headerFooterfontFamily)
        {
            m_Margins = ConvertMarginsToPx(pageSettings.Margins);

              if (pageSettings.Landscape)
            m_PageSize = new Size((int)printTicket.PageMediaSize.Height, (int)printTicket.PageMediaSize.Width);
              else
            m_PageSize = new Size((int)printTicket.PageMediaSize.Width, (int)printTicket.PageMediaSize.Height);

              m_Paginator = paginator;
              m_Paginator.PageSize = new Size(m_PageSize.Width - m_Margins.Left - m_Margins.Right, m_PageSize.Height - m_Margins.Top - m_Margins.Bottom);

              m_Typeface = new Typeface(headerFooterfontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal);
        }
        // ReSharper restore InconsistentNaming

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="report">report document</param>
        /// <param name="data">report data</param>
        /// <exception cref="ArgumentException">Flow document must have a specified page height</exception>
        /// <exception cref="ArgumentException">Flow document must have a specified page width</exception>
        /// <exception cref="ArgumentException">Flow document can have only one report header section</exception>
        /// <exception cref="ArgumentException">Flow document can have only one report footer section</exception>
        public ReportPaginator(ReportDocument report, ReportData data, Action<int, int> PageGeneratedCallBack = null, FlowDocument flowDocument = null)
        {
            _report = report;
            _data = data;
            _pageGeneratedCallBack = PageGeneratedCallBack;

            _flowDocument = flowDocument;
            if (_flowDocument == null) 
                _flowDocument = report.CreateFlowDocument();

            _pageSize = new Size(_flowDocument.PageWidth, _flowDocument.PageHeight);

            if (_flowDocument.PageHeight == double.NaN) throw new ArgumentException("Flow document must have a specified page height");
            if (_flowDocument.PageWidth == double.NaN) throw new ArgumentException("Flow document must have a specified page width");

            _dynamicCache = new ReportPaginatorDynamicCache(_flowDocument);
            ArrayList listPageHeaders = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportHeader));
            if (listPageHeaders.Count > 1) throw new ArgumentException("Flow document can have only one report header section");
            if (listPageHeaders.Count == 1) _blockPageHeader = (SectionReportHeader)listPageHeaders[0];
            ArrayList listPageFooters = _dynamicCache.GetFlowDocumentVisualListByType(typeof(SectionReportFooter));
            if (listPageFooters.Count > 1) throw new ArgumentException("Flow document can have only one report footer section");
            if (listPageFooters.Count == 1) _blockPageFooter = (SectionReportFooter)listPageFooters[0];

            _paginator = ((IDocumentPaginatorSource)_flowDocument).DocumentPaginator;

            // remove header and footer in our working copy
            Block block = _flowDocument.Blocks.FirstBlock;
            while (block != null)
            {
                Block thisBlock = block;
                block = block.NextBlock;
                if ((thisBlock == _blockPageHeader) || (thisBlock == _blockPageFooter)) _flowDocument.Blocks.Remove(thisBlock);
            }

            // get report context values
            _reportContextValues = _dynamicCache.GetFlowDocumentVisualListByInterface(typeof(IInlineContextValue));

            FillData();

            /*Application.Current.Dispatcher.Invoke(new Action(() =>
                {
                    Window aa = new Window();
                    FlowDocumentPageViewer bb = new FlowDocumentPageViewer();
                    bb.Document = _flowDocument;
                    aa.Content = bb;
                    aa.SizeToContent = SizeToContent.WidthAndHeight;
                    aa.ShowDialog();
                }));*/
        }
Пример #12
0
        // --------------------- AdjustFlowDocumentToPage ---------------------
        /// <summary>
        ///   Fits a given flow document to a specified media size.</summary>
        /// <param name="ipd">
        ///   The document paginator containing the flow document.</param>
        /// <param name="pq">
        ///   The print queue the document will be output to.
        public Visual AdjustFlowDocumentToPage(
            DocumentPaginator idp, PrintQueue pq)
        {
            const double inch = 96;

            PrintTicket pt = pq.UserPrintTicket;

            // Get the media size.
            double width = pt.PageMediaSize.Width.Value;
            double height = pt.PageMediaSize.Height.Value;

            // Set the margins.
            double leftmargin = 1.25 * inch;
            double rightmargin = 1.25 * inch;
            double topmargin = 1 * inch;
            double bottommargin = 1 * inch;

            // Calculate the content size.
            double contentwidth = width - leftmargin - rightmargin;
            double contentheight = height - topmargin - bottommargin;
            idp.PageSize = new Size(contentwidth, contentheight);

            DocumentPage p = idp.GetPage(0);

            // Create a wrapper visual for transformation and add extras.
            ContainerVisual page = new ContainerVisual();

            page.Children.Add(p.Visual);

            DrawingVisual title = new DrawingVisual();

            using (DrawingContext ctx = title.RenderOpen())
            {
                Typeface typeface = new Typeface("Times New Roman");
                Brush pen = Brushes.Black;
                FormattedText text =
                    new FormattedText("Page 0",
                            System.Globalization.CultureInfo.CurrentCulture,
                            FlowDirection.LeftToRight, typeface, 14, pen);

                ctx.DrawText(text, new Point(inch / 4, -inch / 2));
            }

            page.Children.Add(title);
            page.Transform = new TranslateTransform(leftmargin, topmargin);

            return page;
        }
Пример #13
0
        public Paginator(FlowDocument document, Definition def)
        {
            this.paginator = ((IDocumentPaginatorSource)document).DocumentPaginator;
            this.definition = def;

            def.Margins = document.PagePadding;

            def.FooterHeight = 40;
            paginator.PageSize = def.ContentSize;

            // Change page size of the document to
            // the size of the content area
            document.ColumnWidth = definition.ContentSize.Width; // Prevent columns
            document.PageWidth = definition.ContentSize.Width;
            document.PageHeight = definition.ContentSize.Height;
            document.PagePadding = new Thickness(0);
        }
        /// <summary>
        ///     Create an instance of AnnotationDocumentPaginator for a given document and annotation store. 
        /// </summary>
        /// <param name="originalPaginator">document to add annotations to</param> 
        /// <param name="annotationStore">store to retrieve annotations from</param> 
        /// <param name="flowDirection"></param>
        public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, AnnotationStore annotationStore, FlowDirection flowDirection) 
        {
            _isFixedContent = originalPaginator is FixedDocumentPaginator || originalPaginator is FixedDocumentSequencePaginator;

            if (!_isFixedContent && !(originalPaginator is FlowDocumentPaginator)) 
                throw new ArgumentException(SR.Get(SRID.OnlyFlowAndFixedSupported));
 
            _originalPaginator = originalPaginator; 
            _annotationStore = annotationStore;
            _locatorManager = new LocatorManager(_annotationStore); 
            _flowDirection = flowDirection;

            // Register for events
            _originalPaginator.GetPageCompleted += new GetPageCompletedEventHandler(HandleGetPageCompleted); 
            _originalPaginator.ComputePageCountCompleted += new AsyncCompletedEventHandler(HandleComputePageCountCompleted);
            _originalPaginator.PagesChanged += new PagesChangedEventHandler(HandlePagesChanged); 
        } 
        public Visual GetNextPortion(Size availableSpace)
        {
            if (_docPaginator == null)
                _docPaginator = GetDocumentPaginator(availableSpace);

            var page = _docPaginator.GetPage(_nextPageToRetrieveNumber++);

            if (page == DocumentPage.Missing)
                return null;

            var pageSize = page.Size;

            if (pageSize.Height > availableSpace.Height || pageSize.Width > availableSpace.Width)
                    throw new ArgumentOutOfRangeException("availableSpace");

            return page.Visual;
        }
Пример #16
0
        public PimpedPaginator(FlowDocument document, Definition def)
        {
            // Create a copy of the flow document,
            // so we can modify it without modifying
            // the original.
            MemoryStream stream = new MemoryStream();
            TextRange sourceDocument = new TextRange(document.ContentStart, document.ContentEnd);
            sourceDocument.Save(stream, DataFormats.Xaml);
            FlowDocument copy = new FlowDocument();
            TextRange copyDocumentRange = new TextRange(copy.ContentStart, copy.ContentEnd);
            copyDocumentRange.Load(stream, DataFormats.Xaml);
            this.paginator = ((IDocumentPaginatorSource)copy).DocumentPaginator;
            this.definition = def;
            paginator.PageSize = def.ContentSize;

            // Change page size of the document to
            // the size of the content area
            copy.ColumnWidth = double.MaxValue; // Prevent columns
            copy.PageWidth = definition.ContentSize.Width;
            copy.PageHeight = definition.ContentSize.Height;
            copy.PagePadding = new Thickness(0);
        }
Пример #17
0
        //IDocumentPaginatorSource flowDocument,
        public static FixedDocument ConvertToFixedDocument(DocumentPaginator documentPaginator)
        {
            FixedDocument fixeddoc = new FixedDocument();

             // DocumentPaginator paginator = documentPaginator;
              if (!documentPaginator.IsPageCountValid)
            documentPaginator.ComputePageCount();

              int pageindex;
              for (pageindex = 0; pageindex < documentPaginator.PageCount; pageindex++)
              {
            Grid grid = new Grid();
            DocumentPageView pageView = new DocumentPageView();
            pageView.DocumentPaginator = documentPaginator;
            pageView.PageNumber = pageindex;

            grid.Children.Add(new Border()
            {
              BorderBrush = Brushes.Black,
              BorderThickness = new Thickness(1),
              HorizontalAlignment = HorizontalAlignment.Center,
              VerticalAlignment = VerticalAlignment.Center,
              Child = pageView
            });

            FixedPage fixedpage = new FixedPage();
            fixedpage.Width = documentPaginator.PageSize.Width;
            fixedpage.Height = documentPaginator.PageSize.Height;
            fixedpage.Children.Add(grid);

            PageContent pc = new PageContent();
            ((IAddChild)pc).AddChild(fixedpage);
            fixeddoc.Pages.Add(pc);
              }

              return fixeddoc;
        }
        public DocumentPaginatorWrapper(DocumentPaginator paginator, PrintableDocumentDefinition definition)
        {
            if (!(paginator.Source is PrintableDocument))
            {
                throw new Exception("This paginator can be used only in PrintableDocument classes");
            }

            _paginator = paginator;
            _definition = definition;

            doc = Source as PrintableDocument;

            var headerSize = GetModelContentSize(doc.DataContext, doc.Header, _definition.PageSize);
            var footerSize = GetModelContentSize(doc.DataContext, doc.Footer, _definition.PageSize);

            _definition.HeaderHeight = double.IsInfinity(headerSize.Height) ? 0 : headerSize.Height;
            _definition.FooterHeight = double.IsInfinity(footerSize.Height) ? 0 : footerSize.Height;

            _paginator.PageSize = _definition.ContentSize;

            ComputePageCount();

            doc.DataSource.PageCount = _paginator.PageCount;
        }
Пример #19
0
 public override void WriteAsync(DocumentPaginator documentPaginator)
 {
     throw new NotSupportedException();
 }
 /// <summary>
 ///     Create an instance of AnnotationDocumentPaginator for a given document and annotation store. 
 /// </summary>
 /// <param name="originalPaginator">document to add annotations to</param> 
 /// <param name="annotationStore">store to retrieve annotations from</param> 
 public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, AnnotationStore annotationStore) : this(originalPaginator, annotationStore, FlowDirection.LeftToRight)
 { 
 }
 /// <summary>
 ///     Create an instance of AnnotationDocumentPaginator for a given document and annotation store.
 /// </summary> 
 /// <param name="originalPaginator">document to add annotations to</param>
 /// <param name="annotationStore">store to retrieve annotations from</param> 
 /// <param name="flowDirection"></param> 
 public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, Stream annotationStore, FlowDirection flowDirection) : this(originalPaginator, new XmlStreamStore(annotationStore), flowDirection)
 { 
 }
        //----------------------------------------------------- 
        //
        //  Public Constructors 
        // 
        //-----------------------------------------------------
 
        #region Public Constructors
        /// <summary>
        ///     Create an instance of AnnotationDocumentPaginator for a given document and annotation store.
        /// </summary> 
        /// <param name="originalPaginator">document to add annotations to</param>
        /// <param name="annotationStore">store to retrieve annotations from</param> 
        public AnnotationDocumentPaginator(DocumentPaginator originalPaginator, Stream annotationStore) : this(originalPaginator, new XmlStreamStore(annotationStore), FlowDirection.LeftToRight) 
        {
        } 
Пример #23
0
 public void PrintDocument(DocumentPaginator documentPaginator, string description)
 {
     DocumentPaginator = documentPaginator;
     Description = description;
 }
Пример #24
0
 public void PrintDocument(DocumentPaginator documentPaginator, string description)
 {
     printDialog.PrintDocument(documentPaginator, description);
 }
Пример #25
0
 public override void Write(DocumentPaginator documentPaginator, PrintTicket printTicket)
 {
     SerializeObjectTree(documentPaginator.Source);
 }
Пример #26
0
 public override void Write(DocumentPaginator documentPaginator)
 {
     Write(documentPaginator, null);
 }
Пример #27
0
		private void GenerateReport()
		{
			using (new TimeCounter("Build report: {0}"))
			using (new WaitWrapper())
			{
				var reportDocument = new ReportDocument();
				using (new TimeCounter("\tGet template: {0}"))
					reportDocument.XamlData = GetXaml();
				using (new TimeCounter("\tGet paginator: {0}"))
					DocumentPaginator = GetPaginator(reportDocument);
				PageNumber = 0;
			}
		}
        /// <summary>
        /// Builds the fixed document.
        /// </summary>
        /// <param name="sourceFlowDocPaginator">The source flow doc paginator.</param>
        /// <param name="size">The size.</param>
        /// <param name="margins">The margins.</param>
        /// <returns>The document.</returns>
        private FixedDocument BuildFixedDocument(DocumentPaginator sourceFlowDocPaginator, Size size, Thickness margins)
        {
            var fixedDocument = new FixedDocument();
            for (int pageNo = 0; pageNo < sourceFlowDocPaginator.PageCount; pageNo++)
            {
                var pageCanvas = new Canvas { Margin = margins };
                this.AddPageBody(sourceFlowDocPaginator, pageNo, pageCanvas, margins);
                this.AddPageToDocument(fixedDocument, pageCanvas, size);
            }

            return fixedDocument;
        }
 /// <summary>
 /// The add page body.
 /// </summary>
 /// <param name="sourceFlowDocPaginator">
 /// The source flow doc paginator.
 /// </param>
 /// <param name="pageNo">
 /// The page no.
 /// </param>
 /// <param name="pageCanvas">
 /// The page canvas.
 /// </param>
 /// <param name="margins">
 /// The margins.
 /// </param>
 private void AddPageBody(
     DocumentPaginator sourceFlowDocPaginator, int pageNo, Canvas pageCanvas, Thickness margins)
 {
     using (var dpv = new DocumentPageView())
     {
         dpv.DocumentPaginator = sourceFlowDocPaginator;
         dpv.PageNumber = pageNo;
         Canvas.SetTop(dpv, margins.Top);
         Canvas.SetLeft(dpv, margins.Left);
         pageCanvas.Children.Add(dpv);
     }
 }
Пример #30
0
 public override void WriteAsync(DocumentPaginator documentPaginator, PrintTicket printTicket, object userState)
 {
     throw new NotSupportedException();
 }