예제 #1
0
        private void ShowPrintPreview()
        {
            // We have to clone the FlowDocument before we use different pagination settings for the export.
            RichTextDocument document = (RichTextDocument)fileService.ActiveDocument;
            FlowDocument     clone    = document.CloneContent();

            clone.ColumnWidth = double.PositiveInfinity;

            // Create a package for the XPS document
            MemoryStream packageStream = new MemoryStream();

            package = Package.Open(packageStream, FileMode.Create, FileAccess.ReadWrite);

            // Create a XPS document with the path "pack://temp.xps"
            PackageStore.AddPackage(new Uri(PackagePath), package);
            xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, PackagePath);

            // Serialize the XPS document
            XpsSerializationManager serializer = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false);
            DocumentPaginator       paginator  = ((IDocumentPaginatorSource)clone).DocumentPaginator;

            serializer.SaveAsXaml(paginator);

            // Get the fixed document sequence
            FixedDocumentSequence documentSequence = xpsDocument.GetFixedDocumentSequence();

            // Create and show the print preview view
            PrintPreviewViewModel printPreviewViewModel = printPreviewViewModelFactory.CreateExport().Value;

            printPreviewViewModel.Document = documentSequence;
            previousView = shellViewModel.ContentView;
            shellViewModel.ContentView           = printPreviewViewModel.View;
            shellViewModel.IsPrintPreviewVisible = true;
            printPreviewCommand.RaiseCanExecuteChanged();
        }
예제 #2
0
        private void PrintDocument()
        {
            if (printDialogService.ShowDialog())
            {
                // We have to clone the FlowDocument before we use different pagination settings for the export.
                RichTextDocument document = (RichTextDocument)fileService.ActiveDocument;
                FlowDocument     clone    = document.CloneContent();

                printDialogService.PrintDocument(((IDocumentPaginatorSource)clone).DocumentPaginator,
                                                 fileService.ActiveDocument.FileName);
            }
        }