当前位置: 首页>>代码示例>>C#>>正文


C# XpsDocument类代码示例

本文整理汇总了C#中XpsDocument的典型用法代码示例。如果您正苦于以下问题:C# XpsDocument类的具体用法?C# XpsDocument怎么用?C# XpsDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


XpsDocument类属于命名空间,在下文中一共展示了XpsDocument类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetXpsDocument

        public static XpsDocument GetXpsDocument(FlowDocument document)
        {
            //Uri DocumentUri = new Uri("pack://currentTicket_" + new Random().Next(1000).ToString() + ".xps");
            Uri docUri = new Uri("pack://tempTicket.xps");

            var ms = new MemoryStream();
            {
                Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);

                PackageStore.RemovePackage(docUri);
                PackageStore.AddPackage(docUri, package);

                XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, docUri.AbsoluteUri);

                XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDocument), false);

                DocumentPaginator docPage = ((IDocumentPaginatorSource)document).DocumentPaginator;

                //docPage.PageSize = new System.Windows.Size(PageWidth, PageHeight);
                //docPage.PageSize = new System.Windows.Size(document.PageWidth, document.PageHeight);

                rsm.SaveAsXaml(docPage);

                return xpsDocument;
            }
        }
开发者ID:cackharot,项目名称:SwizSales,代码行数:26,代码来源:PrintHelper.cs

示例2: SaveXPS

        public static bool SaveXPS(FixedPage page, bool isSaved)
        {
            FixedDocument fixedDoc = new FixedDocument();//创建一个文档
            fixedDoc.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11);

            PageContent pageContent = new PageContent();
            ((IAddChild)pageContent).AddChild(page);
            fixedDoc.Pages.Add(pageContent);//将对象加入到当前文档中

            string containerName = GetXPSFromDialog(isSaved);
            if (containerName != null)
            {
                try
                {
                    File.Delete(containerName);
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message);
                }

                XpsDocument _xpsDocument = new XpsDocument(containerName, FileAccess.Write);

                XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);
                xpsdw.Write(fixedDoc);//写入XPS文件
                _xpsDocument.Close();
                return true;
            }
            else return false;
        }
开发者ID:mydipcom,项目名称:MEIKReport,代码行数:30,代码来源:FileHelper.cs

示例3: Window2_Loaded

 void Window2_Loaded(object sender, RoutedEventArgs e)
 {
     //throw new NotImplementedException();
     XpsDocument xpsdoc = new XpsDocument("xml.xps", System.IO.FileAccess.Read);
     FixedDocumentSequence fds = xpsdoc.GetFixedDocumentSequence();
     documentViewer.Document = fds.References[0].GetDocument(true);
 }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:7,代码来源:Window2.xaml.cs

示例4: Export

        /// <summary>
        /// Exports the specified plot model to an xps file.
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="fileName">The file name.</param>
        /// <param name="width">The width.</param>
        /// <param name="height">The height.</param>
        /// <param name="background">The background color.</param>
        public static void Export(IPlotModel model, string fileName, double width, double height, OxyColor background)
        {
            using (var xpsPackage = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite))
            {
                using (var doc = new XpsDocument(xpsPackage))
                {
                    var canvas = new Canvas { Width = width, Height = height, Background = background.ToBrush() };
                    canvas.Measure(new Size(width, height));
                    canvas.Arrange(new Rect(0, 0, width, height));

                    var rc = new ShapesRenderContext(canvas);
#if !NET35
                    rc.TextFormattingMode = TextFormattingMode.Ideal;
#endif

                    model.Update(true);
                    model.Render(rc, width, height);

                    canvas.UpdateLayout();

                    var xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);
                    xpsdw.Write(canvas);
                }
            }
        }
开发者ID:benjaminrupp,项目名称:oxyplot,代码行数:33,代码来源:XpsExporter.cs

示例5: PreviewWindow

        public PreviewWindow(CustomDocumentPaginator documentPaginator)
        {
            InitializeComponent();

            //xps
            stream = new MemoryStream();

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

            var uri = new Uri(@"memorystream://myXps.xps");
            //already in packagestore, so remove
            if (PackageStore.GetPackage(uri) != null)
            {
                PackageStore.RemovePackage(uri);
            }
            PackageStore.AddPackage(uri, package);
            var xpsDoc = new XpsDocument(package);

            xpsDoc.Uri = uri;
            XpsDocument.CreateXpsDocumentWriter(xpsDoc).Write(documentPaginator);

            FixedDocumentSequence fds = xpsDoc.GetFixedDocumentSequence();

            dv1.Document = (IDocumentPaginatorSource)fds;
        }
开发者ID:Leth3,项目名称:pract,代码行数:25,代码来源:PreviewWindow.xaml.cs

示例6: SaveToPdf

        public static void SaveToPdf(this FlowDocument flowDoc, string filename)
        {
            MemoryStream xamlStream = new MemoryStream();
            XamlWriter.Save(flowDoc, xamlStream);
            File.WriteAllBytes("d:\\file.xaml", xamlStream.ToArray());

            IDocumentPaginatorSource text = flowDoc as IDocumentPaginatorSource;
            xamlStream.Close();

            MemoryStream memoryStream = new MemoryStream();
            Package pkg = Package.Open(memoryStream, FileMode.Create, FileAccess.ReadWrite);

            string pack = "pack://temp.xps";
            PackageStore.AddPackage(new Uri(pack), pkg);

            XpsDocument doc = new XpsDocument(pkg, CompressionOption.SuperFast, pack);
            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
            DocumentPaginator pgn = text.DocumentPaginator;
            rsm.SaveAsXaml(pgn);

            MemoryStream xpsStream = new MemoryStream();
            var writer = new XpsSerializerFactory().CreateSerializerWriter(xpsStream);
            writer.Write(doc.GetFixedDocumentSequence());

            MemoryStream outStream = new MemoryStream();
            NiXPS.Converter.XpsToPdf(xpsStream, outStream);
            File.WriteAllBytes("file.pdf", outStream.ToArray());
        }
开发者ID:BlueForeverI,项目名称:DocumentEditorWpf,代码行数:28,代码来源:PdfConvertor.cs

示例7: ShowPrintPreview

        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();
        }
开发者ID:jbe2277,项目名称:waf,代码行数:31,代码来源:PrintController.cs

示例8: window_Loaded

        private void window_Loaded(object sender, RoutedEventArgs e)
        {
            doc = new XpsDocument("ch19.xps", FileAccess.ReadWrite);
            docViewer.Document = doc.GetFixedDocumentSequence();

            service = AnnotationService.GetService(docViewer);
            if (service == null)
            {
                Uri annotationUri = PackUriHelper.CreatePartUri(new Uri("AnnotationStream", UriKind.Relative));
                Package package = PackageStore.GetPackage(doc.Uri);
                PackagePart annotationPart = null;
                if (package.PartExists(annotationUri))
                {                    
                    annotationPart = package.GetPart(annotationUri);
                }
                else                
                {                    
                    annotationPart = package.CreatePart(annotationUri, "Annotations/Stream");
                }

                // Load annotations from the package.
                AnnotationStore store = new XmlStreamStore(annotationPart.GetStream());
                service = new AnnotationService(docViewer);
                service.Enable(store);
                
            }
        }
开发者ID:ittray,项目名称:LocalDemo,代码行数:27,代码来源:XpsAnnotations.xaml.cs

示例9: SaveToFile

        private void SaveToFile()
        {
            if (Directory.Exists(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData") == false)
            { Directory.CreateDirectory(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData"); }

            string destination = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\renderedData\\" + DateTime.Now.Year + DateTime.Now.Month + DateTime.Now.Day + " " +
                DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second + " " + Environment.UserName + " 2dView";

            using (var stream = new FileStream(destination+".xps", FileMode.Create))
            {
                using (var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite))
                {
                    using (var xpsDoc = new XpsDocument(package, CompressionOption.Maximum))
                    {
                        var rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);
                        var paginator = ((IDocumentPaginatorSource)FlowDocViewer.Document).DocumentPaginator;
                        rsm.SaveAsXaml(paginator);
                        rsm.Commit();
                    }
                }
                stream.Position = 0;

                var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(stream);
                XpsConverter.Convert(pdfXpsDoc, destination + ".pdf", 0);
            }


        }
开发者ID:RadSt,项目名称:WPF-App-For-Ref,代码行数:28,代码来源:view2d.xaml.cs

示例10: btnXpsDocumentWriter_Click

        private void btnXpsDocumentWriter_Click(object sender, RoutedEventArgs e)
        {
            using (Package xpsPackage = Package.Open("Out.xps", FileMode.Create,
                           FileAccess.ReadWrite))
            using (XpsDocument doc = new XpsDocument(xpsPackage))
            {

                FixedPage page = new FixedPage();
                Canvas canvas = new Canvas();
                canvas.Width = 600;
                canvas.Height = 400;
                page.Children.Add(canvas);
                Rectangle rect = new Rectangle();
                Canvas.SetLeft(rect, 50);
                Canvas.SetTop(rect, 50);
                rect.Width = 200;
                rect.Height = 100;
                rect.Stroke = Brushes.Black;
                rect.StrokeThickness = 1;
                canvas.Children.Add(rect);
                XpsDocumentWriter documentWriter =
                XpsDocument.CreateXpsDocumentWriter(doc);
                documentWriter.Write(page);

                doc.CoreDocumentProperties.Description = "Rectangle Output";
            }
        }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:27,代码来源:Window3.xaml.cs

示例11: ConvertWordToXps

        public static XpsDocument ConvertWordToXps(string wordFilename, string xpsFilename)
        {
            // Create a WordApplication and host word document
            Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
            try
            {
                wordApp.Documents.Open(wordFilename);

                // To Invisible the word document
                wordApp.Application.Visible = false;

                // Minimize the opened word document
                wordApp.WindowState = WdWindowState.wdWindowStateMinimize;

                Document doc = wordApp.ActiveDocument;

                doc.SaveAs(xpsFilename, WdSaveFormat.wdFormatXPS);

                XpsDocument xpsDocument = new XpsDocument(xpsFilename, FileAccess.Read);

                return xpsDocument;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error occurs, The error message is  " + ex.ToString());
                return null;
            }
            finally
            {
                wordApp.Documents.Close();
                ((_Application)wordApp).Quit(WdSaveOptions.wdDoNotSaveChanges);
            }
        }
开发者ID:koppandiatt,项目名称:faszomxitprojekt,代码行数:33,代码来源:DocumentPrevier.cs

示例12: btnPrint_Click

 private void btnPrint_Click(object sender, EventArgs e)
 {
     //REFACTOR ME
     dtgParentReport.Update();
     System.Windows.Controls.PrintDialog printDialog = new System.Windows.Controls.PrintDialog();
     Nullable<bool> print = printDialog.ShowDialog();
     if (print == true)
     {
         try
         {
             XpsDocument xpsDocument = new XpsDocument("C:\\FixedDocumentSequence.xps", FileAccess.ReadWrite);
             FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence();
             printDialog.PrintDocument(fixedDocSeq.DocumentPaginator, "Test print job");
         }
         catch (UnauthorizedAccessException e1)
         {
             const string message =
                 "Unauthoried to access that printer.";
             const string caption = "Unauthoried Access";
             var result = MessageBox.Show(message, caption,
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
         }
         catch (PrintDialogException e2)
         {
             const string message =
                 "Unknow error occurred.";
             const string caption = "Error Printing";
             var result = MessageBox.Show(message, caption,
                                         MessageBoxButtons.OK,
                                         MessageBoxIcon.Error);
         }
     }
 }
开发者ID:jeffBunce,项目名称:Math-Monkeys-3.0,代码行数:34,代码来源:frmParentReport.cs

示例13: Concat

        public static void Concat(string targetFileName, params string[] filesToConcat)
        {
            var fixedDocumentSequence = new FixedDocumentSequence();

            var tempFileName = Path.GetTempFileName();
            using (var target = new XpsDocument(tempFileName, FileAccess.Write))
            {
                var xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(target);

                if (filesToConcat != null)
                {
                    foreach (var doc in filesToConcat)
                    {
                        Add(doc, fixedDocumentSequence);
                    }
                }

                xpsDocumentWriter.Write(fixedDocumentSequence);
            }

            if (File.Exists(targetFileName))
            {
                File.Delete(targetFileName);
            }
            File.Move(tempFileName, targetFileName);
        }
开发者ID:xxMUROxx,项目名称:Mairegger.Printing,代码行数:26,代码来源:XPSHelper.cs

示例14: InternalCreateFileFromXaml

        private static CreateXpsFileResult InternalCreateFileFromXaml(FrameworkElement template, object dataContext)
        {
            string xpsFile = Path.GetTempFileName() + ".xps";

            using (var container = Package.Open(xpsFile, FileMode.Create))
            using (var document = new XpsDocument(container, CompressionOption.SuperFast))
            {
                var coupon = template;

                coupon.DataContext = dataContext;
                coupon.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                coupon.UpdateLayout();

                var ticket = new PrintTicket()
                {
                    PageMediaSize = new PageMediaSize(coupon.DesiredSize.Width, coupon.DesiredSize.Height)
                };

                XpsDocument.CreateXpsDocumentWriter(document).Write(coupon, ticket);

                return new CreateXpsFileResult()
                {
                    Path = xpsFile,
                    Ticket = ticket
                };
            }
        }
开发者ID:breslavsky,项目名称:queue,代码行数:27,代码来源:XPSUtils.cs

示例15: Print

        public void Print()
        {
            MemoryStream xpsStream = new MemoryStream();
            Package pack = Package.Open(xpsStream, FileMode.CreateNew);

            string inMemPackageName= "memorystream://myXps.xps";
            Uri packageUri = new Uri(inMemPackageName);

            PackageStore.AddPackage(packageUri, pack);

            XpsDocument xpsDoc = new XpsDocument(pack, CompressionOption.SuperFast, inMemPackageName);

            XpsDocumentWriter xpsDocWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

            FixedDocument doc = CreatePawnTicket();
            //DocumentPaginator documentPaginator = (FlowDocument)IDocumentPaginatorSource).DocumentPaginator;
            //documentPaginator = New DocumentPaginatorWrapper(documentPaginator, pageSize, margin, documentStatus, firstPageHeaderPath, primaryHeaderPath)
            xpsDocWriter.Write(doc);

            //Package package =
            //XpsDocument xpsd = new XpsDocument((filename, FileAccess.ReadWrite);
            //    //XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
            //    xw.Write(doc);
            //    xpsd.Close();
        }
开发者ID:RayMetz100,项目名称:hyperpawn,代码行数:25,代码来源:PawnTicketTry1.cs


注:本文中的XpsDocument类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。