Exemple #1
0
        /// <summary>
        /// Set up Document
        /// </summary>
        /// <remarks>
        /// if you use this class both @mainview & @reportcontrol for datacontext
        /// do not call this function at intitialize method.
        /// </remarks>
        public void SetDoc()
        {
            // Set the ReportTemplateContorl to fixedpage
            FixedDocument fixedDoc = new FixedDocument();
            // ReportCtrl report = new ReportCtrl();

            ReportCtrl myReport = new ReportCtrl();

            myReport.DataContext = this;

            PageContent pageContent = new PageContent();
            FixedPage   fixedPage   = new FixedPage();

            fixedPage.Children.Add(myReport);
            ((IAddChild)pageContent).AddChild(fixedPage);
            fixedDoc.Pages.Add(pageContent);


            // this.PagenatorSource = fixedDoc.DocumentPaginator.Source;
            this.FixedDocumentSequence = fixedDoc.DocumentPaginator.Source;
        }
        public static void Print(MainWindowViewModel vm)
        {
            // Set the ReportTemplateContorl to fixedpage
            FixedDocument fixedDoc = new FixedDocument();
            ReportCtrl    report   = new ReportCtrl();

            UserControl ReportToPrint = report as UserControl;

            ReportToPrint.DataContext = vm;

            PageContent pageContent = new PageContent();
            FixedPage   fixedPage   = new FixedPage();

            fixedPage.Children.Add(ReportToPrint);
            ((IAddChild)pageContent).AddChild(fixedPage);
            fixedDoc.Pages.Add(pageContent);

            // Print page
            if (!SendFixedDocumentToPrinter(fixedDoc))
            {
                return;
            }

            // Save fixeddocument as xps file
            string fileName = @"C:\temp\sample_report.xps";

            // Set up package
            Package package = Package.Open(fileName, System.IO.FileMode.Create);

            // Set up XpsDocument object
            XpsDocument       xpsDoc = new XpsDocument(package);
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

            // write to xps file wpt fixed doc
            writer.Write(fixedDoc.DocumentPaginator);


            xpsDoc.Close();
            package.Close();
        }