• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# XpsDocument类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: cmdShowFlow_Click

        private void cmdShowFlow_Click(object sender, RoutedEventArgs e)
        {
            // Load the XPS content into memory.
            MemoryStream ms = new MemoryStream();
            Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
            Uri DocumentUri = new Uri("pack://InMemoryDocument.xps");
            PackageStore.AddPackage(DocumentUri, package);
            XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.Fast,
                DocumentUri.AbsoluteUri);
                        
            // Load the XPS content into a temporary file (alternative approach).
            //if (File.Exists("test2.xps")) File.Delete("test2.xps");
            //    XpsDocument xpsDocument = new XpsDocument("test2.xps", FileAccess.ReadWrite);

            using (FileStream fs = File.Open("FlowDocument1.xaml", FileMode.Open))
            {
                FlowDocument doc = (FlowDocument)XamlReader.Load(fs);                           
                XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

                writer.Write(((IDocumentPaginatorSource)doc).DocumentPaginator);

                // Display the new XPS document in a viewer.
                docViewer.Document = xpsDocument.GetFixedDocumentSequence();
                xpsDocument.Close();
            }
        }
开发者ID:ittray,项目名称:LocalDemo,代码行数:26,代码来源:Xps.xaml.cs


示例17: ExtractText

        // Test
        public static string ExtractText(string path)
        {
            XpsDocument _xpsDocument = new XpsDocument(path, System.IO.FileAccess.Read);
            IXpsFixedDocumentSequenceReader fixedDocSeqReader
                = _xpsDocument.FixedDocumentSequenceReader;
            IXpsFixedDocumentReader _document = fixedDocSeqReader.FixedDocuments[0];

            IXpsFixedPageReader _page
                = _document.FixedPages[0];
            StringBuilder _currentText = new StringBuilder();
            System.Xml.XmlReader _pageContentReader = _page.XmlReader;
            if (_pageContentReader != null)
            {
                while (_pageContentReader.Read())
                {
                    if (_pageContentReader.Name == "Glyphs")
                    {
                        if (_pageContentReader.HasAttributes)
                        {
                            if (_pageContentReader.GetAttribute("UnicodeString") != null)
                            {
                                _currentText.
                                  Append(_pageContentReader.
                                  GetAttribute("UnicodeString") + "\n");
                            }
                        }
                    }
                }
            }
               return _currentText.ToString();
        }
开发者ID:enntwo,项目名称:EventMessenger,代码行数:32,代码来源:XpsConverter.cs


示例18: btnXmlWriter_Click

 private void btnXmlWriter_Click(object sender, RoutedEventArgs e)
 {
     using (XpsDocument xpsDoc = new XpsDocument("Out.xps", FileAccess.Write))
     {
         IXpsFixedDocumentSequenceWriter sequenceWriter =
         xpsDoc.AddFixedDocumentSequence();
         IXpsFixedDocumentWriter docWriter =
         sequenceWriter.AddFixedDocument();
         IXpsFixedPageWriter pageWriter = docWriter.AddFixedPage();
         XmlWriter xmlWriter = pageWriter.XmlWriter;
         xmlWriter.WriteStartElement("FixedPage");
         xmlWriter.WriteAttributeString("xmlns",
                      "http://schemas.microsoft.com/xps/2005/06");
         xmlWriter.WriteAttributeString("Width", "600");
         xmlWriter.WriteAttributeString("Height", "400");
         xmlWriter.WriteAttributeString("xml:lang", "ko-KR");
         xmlWriter.WriteStartElement("Path");
         xmlWriter.WriteAttributeString("Data",
                             "M 10,10 L 150,200 500,300 555,387 z");
         xmlWriter.WriteAttributeString("Fill", "#ffff0000");
         xmlWriter.WriteEndElement();
         xmlWriter.WriteEndElement();
         pageWriter.Commit();
         docWriter.Commit();
         sequenceWriter.Commit();
     }
 }
开发者ID:gawallsibya,项目名称:BIT_MFC-CShap-DotNet,代码行数:27,代码来源:Window3.xaml.cs


示例19: Window_Loaded

 private void Window_Loaded(object sender, EventArgs e)
 {            
     XpsDocument doc = new XpsDocument("test.xps", FileAccess.ReadWrite);
     docViewer.Document = doc.GetFixedDocumentSequence();
     
     doc.Close();
 }
开发者ID:ssickles,项目名称:archive,代码行数:7,代码来源:Xps.xaml.cs


示例20: Show

 public override void Show(System.Windows.Controls.ContentControl contentControl, object writer)
 {
     this.m_XpsDocument = new XpsDocument(this.FullFileName, System.IO.FileAccess.Read);
     System.Windows.Controls.DocumentViewer documentViewer = new System.Windows.Controls.DocumentViewer();
     documentViewer.Loaded += new System.Windows.RoutedEventHandler(DocumentViewer_Loaded);
     documentViewer.Document = this.m_XpsDocument.GetFixedDocumentSequence();
     contentControl.Content = documentViewer;
 }
开发者ID:WilliamCopland,项目名称:YPILIS,代码行数:8,代码来源:XpsCaseDocument.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# XrmFakedContext类代码示例发布时间:2022-05-24
下一篇:
C# XmlWriterTestHelper类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap