Esempio n. 1
0
 private void Window_Loaded(object sender, EventArgs e)
 {            
     XpsDocument doc = new XpsDocument("test.xps", FileAccess.ReadWrite);
     docViewer.Document = doc.GetFixedDocumentSequence();
     
     doc.Close();
 }
Esempio n. 2
0
        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;
        }
 public void ViewDocument(string fileName)
 {
     if (System.IO.File.Exists(fileName) == true)
     {
         XpsDocument xpsDocument = new XpsDocument(fileName, System.IO.FileAccess.Read);
         this.Viewer.Document = xpsDocument.GetFixedDocumentSequence();
         xpsDocument.Close();
     }
 }
Esempio n. 4
0
        private void LoadQuickStartToDocummentViewer()
        {
            string fileName = @"Quick Start Guide.xps";
            XpsDocument document = new XpsDocument(fileName, FileAccess.Read);
            this.documentViewer.Document = document.GetFixedDocumentSequence();
            document.Close();

            this.documentViewer.FitToWidth();

            var contentHost = this.documentViewer.Template.FindName("PART_ContentHost", this.documentViewer) as ScrollViewer;
            var grid = contentHost?.Parent as Grid;
            grid?.Children.RemoveAt(0);
        }
    private void button2_Click(object sender, RoutedEventArgs e)
    {
      string filename = "Test.txt";
      File.Delete(filename);
      XpsDocument doc = new XpsDocument(filename, System.IO.FileAccess.ReadWrite);
      XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(doc);

      //PageContent content = CreateFifthPageContent();
      FixedPage page = CreateFifthPageContent();
      //page.conten
//      page.
      xpsdw.Write(page);
      doc.Close();
    }
 internal void SaveToFile(string fileName)
 {
     Transform transform = canvasContainer.LayoutTransform;
     canvasContainer.LayoutTransform = null;
     Size size = new Size(canvasContainer.Width, canvasContainer.Height);
     canvasContainer.Measure(size);
     canvasContainer.Arrange(new Rect(size));
     Package package = Package.Open(fileName, System.IO.FileMode.Create);
     XpsDocument doc = new XpsDocument(package);
     XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
     writer.Write(canvasContainer);
     doc.Close();
     package.Close();
     canvasContainer.LayoutTransform = transform;
 }
Esempio n. 7
0
        /// <summary>
        /// Loads the specified DocumentPaginatorWrapper document for print preview.
        /// </summary>
        public void LoadDocument(DocumentPaginatorWrapper document)
        {
            m_Document = document;
            string temp = System.IO.Path.GetTempFileName();
            if (File.Exists(temp))
            {
                File.Delete(temp);
            }

            XpsDocument xpsDoc = new XpsDocument(temp, FileAccess.ReadWrite);
            XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
            xpsWriter.Write(document);

            documentViewer.Document = xpsDoc.GetFixedDocumentSequence();
            xpsDoc.Close();
        }
        /// <summary>
        /// Store a visual in an array of bytes.
        /// </summary>
        /// <param name="v">The <see cref="Visual"/> to serialise.</param>
        /// <returns>The serialised <see cref="Visual"/>.</returns>
        public static byte[] SaveVisualToByteArray(this Visual v)
        {
            // Open new package
            MemoryStream stream = new MemoryStream();
            Package package = Package.Open(stream, FileMode.Create);
            // Create new xps document based on the package opened
            XpsDocument doc = new XpsDocument(package);
            // Create an instance of XpsDocumentWriter for the document
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
            // Write the Visual to the document
            writer.Write(v);
            // Close document
            doc.Close();
            // Close package
            package.Close();

            return stream.ToArray();
        }
Esempio n. 9
0
        private void Xps_Click(object sender, RoutedEventArgs e)
        {
            FixedPage page = new FixedPage() { Background = Brushes.White, Width = Dpi * PaperWidth, Height = Dpi * PaperHeight };

            TextBlock tbTitle = new TextBlock { Text = "My InkCanvas Sketch", FontSize = 24, FontFamily = new FontFamily("Arial") };
            FixedPage.SetLeft(tbTitle, Dpi * 0.75);
            FixedPage.SetTop(tbTitle, Dpi * 0.75);
            page.Children.Add((UIElement)tbTitle);

            var toPrint = myInkCanvasBorder;
            myGrid.Children.Remove(myInkCanvasBorder);

            FixedPage.SetLeft(toPrint, Dpi * 2);
            FixedPage.SetTop(toPrint, Dpi * 2);
            page.Children.Add(toPrint);

            Size sz = new Size(Dpi * PaperWidth, Dpi * PaperHeight);
            page.Measure(sz);
            page.Arrange(new Rect(new Point(), sz));
            page.UpdateLayout();

            var filepath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "PrintingTest");
            if (!File.Exists(filepath))
                Directory.CreateDirectory(filepath);
            var filename = System.IO.Path.Combine(filepath, "myXpsFile.xps");

            FixedDocument doc = new FixedDocument();

            PageContent pageContent = new PageContent();
            ((System.Windows.Markup.IAddChild)pageContent).AddChild(page);
            doc.Pages.Add(pageContent);

            XpsDocument xpsd = new XpsDocument(filename, FileAccess.Write);
            XpsDocument.CreateXpsDocumentWriter(xpsd).Write(doc);               //requires System.Printing namespace

            xpsd.Close();

            PrintDialog printDialog = new PrintDialog();
            if (printDialog.ShowDialog() == true)
                printDialog.PrintQueue.AddJob("MyInkCanvas print job", filename, true);

            page.Children.Remove(toPrint);
            myGrid.Children.Add(toPrint);
        }
        /// <summary>
        /// Loads the specified FlowDocument document for print preview.
        /// </summary>
        public void LoadDocument(FlowDocument document)
        {
            mDocument = document;

              string temp = System.IO.Path.GetTempFileName();

              if (File.Exists(temp) == true)
            File.Delete(temp);

              XpsDocument xpsDoc = new XpsDocument(temp, FileAccess.ReadWrite);

              XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

              xpsWriter.Write(((FlowDocument)document as IDocumentPaginatorSource).DocumentPaginator);

              documentViewer.Document = xpsDoc.GetFixedDocumentSequence();

              xpsDoc.Close();
        }
Esempio n. 11
0
        private void cmdShowFlow_Click(object sender, RoutedEventArgs e)
        {
            
            if (File.Exists("test2.xps")) File.Delete("test2.xps");

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

                XpsDocument xpsDocument = new XpsDocument("test2.xps", FileAccess.ReadWrite);
                XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

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

                // Display the new XPS document in a viewer.
                docViewer.Document = xpsDocument.GetFixedDocumentSequence();
                xpsDocument.Close();
            }
        }
Esempio n. 12
0
        /// <summary>
        /// Convert a FixedDocument to an XPS file.
        /// </summary>
        /// <param name="fixedDoc">The FixedDocument to convert.</param>
        /// <param name="outputStream">The output stream.</param>
        public static void ConvertToXps(FixedDocument fixedDoc, Stream outputStream)
        {
            var package = Package.Open(outputStream, FileMode.Create);
            var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
            XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

            // xps documents are built using fixed document sequences
            var fixedDocSeq = new FixedDocumentSequence();
            var docRef = new DocumentReference();
            docRef.BeginInit();
            docRef.SetDocument(fixedDoc);
            docRef.EndInit();
            ((IAddChild)fixedDocSeq).AddChild(docRef);

            // write out our fixed document to xps
            xpsWriter.Write(fixedDocSeq.DocumentPaginator);

            xpsDoc.Close();
            package.Close();
        }
Esempio n. 13
0
        public static void Print(List<object> printCollection, 
            String FinalTargetFileName, String HeadLineText, String PrintPageOrientation = "Portrait")
            {

            PrintDialog PrtDialog = new PrintDialog();
            LocalPrintServer LPS = new LocalPrintServer();
            PrintQueue DefaultPrinterQueue = LocalPrintServer.GetDefaultPrintQueue();
            PrintTicket DefaultTicket = DefaultPrinterQueue.DefaultPrintTicket;
            PrintCapabilities DefaultCapabilities = DefaultPrinterQueue.GetPrintCapabilities(DefaultTicket);

            if (PrintPageOrientation == "Landscape")
                PrtDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
            else
                PrtDialog.PrintTicket.PageOrientation = PageOrientation.Portrait;

            PAPER_SIZE_WIDTH = PrtDialog.PrintableAreaWidth;
            PAPER_SIZE_HEIGHT = PrtDialog.PrintableAreaHeight;
            TOP_MARGIN = PrtDialog.PrintableAreaHeight * 0.08;
            SIDE_MARGIN = PrtDialog.PrintableAreaWidth * 0.08;

            double MaxOWidth = PAPER_SIZE_WIDTH - (2 * SIDE_MARGIN);
            double MaxOHeight = PAPER_SIZE_HEIGHT - (2 * TOP_MARGIN) - 20;

            FixedDocument PageDocumentToPrint = new FixedDocument();
            DefinitionsForPrintWithXAMLControls XAMLDefinitionsForOnePage = GenerateNewContent(PageDocumentToPrint);
            ObservableCollection<object> PageCollection = XAMLDefinitionsForOnePage.GlobalContainer.ItemsSource as ObservableCollection<object>;
            int NumberOfPages = CreatePages (XAMLDefinitionsForOnePage, PageDocumentToPrint, MaxOHeight, printCollection,
                PageCollection, HeadLineText);



            XpsDocument XpsDoc = new XpsDocument(FinalTargetFileName, FileAccess.Write);
            XpsDocumentWriter XpsWriter = XpsDocument.CreateXpsDocumentWriter(XpsDoc);
            XpsWriter.Write(PageDocumentToPrint.DocumentPaginator);
            XpsDoc.Close();
		
            }
Esempio n. 14
0
        /// <summary>
        /// Export the currently displayed content to an xps (vector format) file.
        /// </summary>
        /// <param name="path">The .xps file to export to.</param>
        /// <remarks>
        /// Adapted from http://denisvuyka.wordpress.com/2007/12/03/wpf-diagramming-saving-you-canvas-to-image-xps-document-or-raw-xaml/.
        /// </remarks>
        public void ExportXPS(Uri path)
        {
            if (path == null) return;

            // Save current canvas transorm
            System.Windows.Media.Transform transform = this.LayoutTransform;
            Thickness oldMargin = this.Margin;
            // Temporarily reset the layout transform before saving
            this.LayoutTransform = null;
            this.Margin = new Thickness(0);

            // Get the size of canvas
            double w = this.Width.CompareTo(double.NaN) == 0 ? this.ActualWidth : this.Width;
            double h = this.Height.CompareTo(double.NaN) == 0 ? this.ActualHeight : this.Height;
            Size size = new Size(w, h);
            // Measure and arrange elements
            this.Measure(size);
            this.Arrange(new Rect(size));

            // Open new package
            Package package = Package.Open(path.LocalPath, FileMode.Create);
            // Create new xps document based on the package opened
            XpsDocument doc = new XpsDocument(package);
            // Create an instance of XpsDocumentWriter for the document
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
            // Write the canvas (as Visual) to the document
            writer.Write(this);
            // Close document
            doc.Close();
            // Close package
            package.Close();

            // Restore previously saved layout
            this.Margin = oldMargin;
            this.LayoutTransform = transform;
        }
Esempio n. 15
0
      private void ExportCards()
      {
         var dlg = new Microsoft.Win32.SaveFileDialog();
         dlg.FileName = "Scrum Cards.xps";
         dlg.DefaultExt = ".xps";
         dlg.Filter = "XPS Documents (.xps)|*.xps";
         dlg.OverwritePrompt = true;

         var result = dlg.ShowDialog();

         if (result == false)
            return;

         var document = GenerateDocument();
         var filename = dlg.FileName;
         if (File.Exists(filename))
            File.Delete(filename);

         using (var xpsd = new XpsDocument(filename, FileAccess.ReadWrite))
         {
            var xw = XpsDocument.CreateXpsDocumentWriter(xpsd);
            xw.Write(document);
            xpsd.Close();
         }
      }
        //*************************************************************************
        //  Method: SaveToXps()
        //
        /// <summary>
        /// Saves the graph to the specified XPS file.
        /// </summary>
        ///
        /// <param name="imageSize">
        /// Size of the XPS image, in WPS units.
        /// </param>
        ///
        /// <param name="fileName">
        /// File name to save to.
        /// </param>
        ///
        /// <remarks>
        /// This could conceivably be put in the base-class NodeXLControl class,
        /// but that would force all users of the control to add references to the
        /// XPS assemblies.
        /// </remarks>
        //*************************************************************************
        public void SaveToXps(
            Size imageSize,
            String fileName
            )
        {
            Debug.Assert( !String.IsNullOrEmpty(fileName) );
            AssertValid();

            CheckIfLayingOutGraph("SaveToXps");

            // This control will be rehosted by a FixedPage.  It can't be a child
            // of logical trees, so disconnect it from its parent after saving the
            // current vertex locations.

            LayoutSaver oLayoutSaver = new LayoutSaver(this.Graph);

            Debug.Assert(this.Parent is Panel);
            Panel oParentPanel = (Panel)this.Parent;
            UIElementCollection oParentChildren = oParentPanel.Children;
            Int32 iChildIndex = oParentChildren.IndexOf(this);
            oParentChildren.Remove(this);

            GraphImageCenterer oGraphImageCenterer = new GraphImageCenterer(this);

            FixedDocument oFixedDocument = new FixedDocument();
            oFixedDocument.DocumentPaginator.PageSize = imageSize;
            PageContent oPageContent = new PageContent();

            FixedPage oFixedPage = new FixedPage();
            oFixedPage.Width = imageSize.Width;
            oFixedPage.Height = imageSize.Height;

            this.Width = imageSize.Width;
            this.Height = imageSize.Height;

            // Adjust the control's translate transforms so that the image will be
            // centered on the same point on the graph that the control is centered
            // on.

            oGraphImageCenterer.CenterGraphImage(imageSize);

            oFixedPage.Children.Add(this);
            oFixedPage.Measure(imageSize);

            oFixedPage.Arrange(new System.Windows.Rect(
            new System.Windows.Point(), imageSize) );

            oFixedPage.UpdateLayout();

            ( (System.Windows.Markup.IAddChild)oPageContent ).AddChild(
            oFixedPage);

            oFixedDocument.Pages.Add(oPageContent);

            try
            {
            XpsDocument oXpsDocument = new XpsDocument(fileName,
                FileAccess.Write);

            XpsDocumentWriter oXpsDocumentWriter =
                XpsDocument.CreateXpsDocumentWriter(oXpsDocument);

            oXpsDocumentWriter.Write(oFixedDocument);
            oXpsDocument.Close();
            }
            finally
            {
            // Reconnect the NodeXLControl to its original parent.  Reset the
            // size to Auto in the process.

            oFixedPage.Children.Remove(this);
            this.Width = Double.NaN;
            this.Height = Double.NaN;
            oGraphImageCenterer.RestoreCenter();
            oParentChildren.Insert(iChildIndex, this);

            // The graph may have shrunk when it was connected to the
            // FixedPage, and even though it will be expanded to its original
            // dimensions when UpdateLayout() is called below, the layout may
            // have lost "resolution" and the results may be poor.
            //
            // Fix this by restoring the original layout and redrawing the
            // graph.

            this.UpdateLayout();
            oLayoutSaver.RestoreLayout();
            this.DrawGraph(false);
            }
        }
Esempio n. 17
0
        public void SaveCurrentDocument()
        {
            // Configure save file dialog box
            var dlg = new Microsoft.Win32.SaveFileDialog
            {
                FileName = "Faktura",
                DefaultExt = ".xps",
                Filter = "XPS Documents (.xps)|*.xps"
            };

            // Show save file dialog box
            Nullable<bool> result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;

                FixedDocument doc = CreateMyWPFControlReport();
                File.Delete(filename);
                var xpsd = new XpsDocument(filename, FileAccess.ReadWrite);
                XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(xpsd);

                xw.Write(doc);
                xpsd.Close();
            }
        }
Esempio n. 18
0
 private void UnloadedHandler(object sender, RoutedEventArgs e)
 {
     xpsDocument?.Close();
     PackageStore.RemovePackage(new Uri(PackagePath));
     package.Close();
 }
Esempio n. 19
0
    /// <summary>
    /// Renders the current visual as a FixedPage and save it as XPS file.
    /// </summary>
    public void SaveXps()
    {
      XpsDocument xpsDocument = new XpsDocument(Path.Combine(OutputDirectory, Name + ".xps"), FileAccess.ReadWrite);
      PageContent pageContent = new PageContent();

      FixedPage fixedPage = new FixedPage();
      fixedPage.Width = WidthInPU;
      fixedPage.Height = HeightInPU;
      fixedPage.Background = Brushes.Transparent;

      // Visuals needs a UIElement as drawing container
      VisualPresenter presenter = new VisualPresenter();
      presenter.AddVisual(this.visual);

      FixedPage.SetLeft(presenter, 0);
      FixedPage.SetTop(presenter, 0);
      fixedPage.Children.Add(presenter);

      // Perform layout
      Size size = new Size(WidthInPU, HeightInPU);
      fixedPage.Measure(size);
      fixedPage.Arrange(new Rect(new Point(), size));
      fixedPage.UpdateLayout();

      ((IAddChild)pageContent).AddChild(fixedPage);

      FixedDocument fixedDocument = new FixedDocument();
      fixedDocument.DocumentPaginator.PageSize = size;
      fixedDocument.Pages.Add(pageContent);

      // Save as XPS file
      XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
      xpsWriter.Write(fixedDocument);
      xpsDocument.Close();

      // Must call at least two times GC.Collect this to get access to the xps file even I write synchronously. This is a bug in WPF.
      // Vista 64 .NET 3.5 SP1 installed
      xpsDocument = null;
      xpsWriter = null;
      GC.Collect(10, GCCollectionMode.Forced);
      GC.Collect(10, GCCollectionMode.Forced);
      //GC.Collect(10, GCCollectionMode.Forced);
      //GC.Collect(10, GCCollectionMode.Forced);
    }
        /// <summary>
        /// 针对FLowDocument对象生成PDF文件
        /// </summary>
        /// <param name="reportTempl"></param>
        /// <param name="pdfFile"></param>
        /// <param name="reportModel"></param>
        private void ExportFlowDocumentPDF(string reportTempl, string pdfFile, ShortFormReport reportModel,string pagesize=null)
        {
            string xpsFile = dataFolder + System.IO.Path.DirectorySeparatorChar + person.Code + ".xps";
            if (File.Exists(xpsFile))
            {
                File.Delete(xpsFile);
            }

            FlowDocument page = (FlowDocument)PrintPreviewWindow.LoadFlowDocumentAndRender(reportTempl, reportModel,pagesize);
            try
            {
                LoadDataForFlowDocument(page, reportModel);
            }
            catch { }
            XpsDocument xpsDocument = new XpsDocument(xpsFile, FileAccess.ReadWrite);
            //将flow document写入基于内存的xps document中去
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
            writer.Write(((IDocumentPaginatorSource)page).DocumentPaginator);
            xpsDocument.Close();
            if (File.Exists(pdfFile))
            {
                File.Delete(pdfFile);
            }
            PDFTools.SavePDFFile(xpsFile, pdfFile);
        }
 /// <summary>
 ///针对FixedPage对象生成PDF 
 /// </summary>
 /// <param name="reportTempl"></param>
 /// <param name="pdfFile"></param>
 /// <param name="reportModel"></param>
 private void ExportPDF(string reportTempl,string pdfFile,ShortFormReport reportModel)
 {
     string xpsFile = dataFolder + System.IO.Path.DirectorySeparatorChar + person.Code + ".xps";
     //string userTempPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
     //string xpsFile = userTempPath + System.IO.Path.DirectorySeparatorChar + person.Code + ".xps";
     if (File.Exists(xpsFile))
     {
         File.Delete(xpsFile);
     }
     
     FixedPage page = (FixedPage)PrintPreviewWindow.LoadFixedDocumentAndRender(reportTempl, reportModel);
     
     XpsDocument xpsDocument = new XpsDocument(xpsFile, FileAccess.ReadWrite);
     //将flow document写入基于内存的xps document中去
     XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
     writer.Write(page);
     xpsDocument.Close();
     if (File.Exists(pdfFile))
     {
         File.Delete(pdfFile);
     }
     PDFTools.SavePDFFile(xpsFile, pdfFile);            
 }
Esempio n. 22
0
        public static RTDocument PPT2RTDocument(string pptFilename)
        {
            //Pri2: Investigate where BasePath is and where we should be putting it in more depth.
            //      Concerned that we're creating directories there that never get cleaned up...
            if (!Directory.Exists(tfc.BasePath))
            {
                Directory.CreateDirectory(tfc.BasePath);
            }
            // Initialize PowerPoint app
            //ApplicationClass ppt = new ApplicationClass();

            // Open the PPT file
            //Presentation presentation = ppt.Presentations.Open(pptFilename, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);
            //Slides slides = presentation.Slides;
            XpsDocument           xpsDoc = new XpsDocument(pptFilename, FileAccess.Read);
            FixedDocumentSequence docSeq = new FixedDocumentSequence();

            docSeq = xpsDoc.GetFixedDocumentSequence();
            DocumentPaginator paginator = docSeq.DocumentPaginator;
            int pages = paginator.PageCount;
            // Set up the document
            RTDocument rtDoc = new RTDocument();

            rtDoc.Identifier = Guid.NewGuid();
            //rtDoc.Metadata.Title = GetPresentationProperty(xpsDoc, "Title");
            //rtDoc.Metadata.Creator = GetPresentationProperty(xpsDoc, "Author");

            // Create shared MemoryStream to minimize mem usage
            MemoryStream ms = new MemoryStream();

            //Iterate through the pages
            //int i = 0;
            //foreach(Slide s in slides)
            //{
            //    // Set the page properties
            //    Page p = new Page();
            //    p.Identifier = Guid.NewGuid();
            //    p.Image = GetSlideImage(s, ms);
            //    if (p.Image is Metafile)
            //    {
            //        p.MimeType = "image/x-wmf";
            //    }
            //    if (p.Image is Bitmap)
            //    {
            //        p.MimeType = "image/png";
            //    }
            //    rtDoc.Resources.Pages.Add(p.Identifier, p);

            //    // TODO, slice in RegionBuilder code from Presenter work...

            //    // Set the TOCNode properties for the page
            //    TOCNode tn = new TOCNode();
            //    tn.Title = GetSlideTitle(s);
            //    tn.Resource = p;
            //    tn.ResourceIdentifier = p.Identifier;
            //    //Pri2: Shouldn't this be a byte[] containing the PNG stream instead of a System.Drawing.Image?
            //    tn.Thumbnail = RTDocumentHelper.GetThumbnailFromImage(p.Image);
            //    rtDoc.Organization.TableOfContents.Add(tn);
            //    i++;
            //}
            for (int pageNum = 0; pageNum != pages; ++pageNum)
            {
                using (DocumentPage docPage = paginator.GetPage(pageNum))
                {
                    Page p = new Page();
                    p.Identifier = Guid.NewGuid();
                    p.Image      = GetSlideImage(docPage, ms);
                    if (p.Image is Metafile)
                    {
                        p.MimeType = "image/x-wmf";
                    }
                    if (p.Image is Bitmap)
                    {
                        p.MimeType = "image/png";
                    }
                    rtDoc.Resources.Pages.Add(p.Identifier, p);

                    // TODO, slice in RegionBuilder code from Presenter work...

                    // Set the TOCNode properties for the page
                    TOCNode tn = new TOCNode();
                    //tn.Title = GetSlideTitle(docPage);
                    tn.Resource           = p;
                    tn.ResourceIdentifier = p.Identifier;
                    //Pri2: Shouldn't this be a byte[] containing the PNG stream instead of a System.Drawing.Image?
                    tn.Thumbnail = RTDocumentHelper.GetThumbnailFromImage(p.Image);
                    rtDoc.Organization.TableOfContents.Add(tn);
                }
            }
            // Close PPT
            xpsDoc.Close();
            //if (xpsDoc. == 0)
            //{
            //    ppt.Quit();
            //}

            //ppt = null;

            tfc.Delete();

            return(rtDoc);
        }
Esempio n. 23
0
        public void Save()
        {
            if (Uri == null)
            {
                throw new ArgumentException("Uri has not been specified");
            }

            var xpsDocument = new XpsDocument(Uri.OriginalString, FileAccess.ReadWrite);
            var xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
            xpsDocumentWriter.Write(FixedDocumentSequence);
            xpsDocument.Close();
        }
Esempio n. 24
0
        public void PostXPS(String Location)
        {
            
            FixedDocumentSequence fds = xps.GetFixedDocumentSequence();

            File.Delete(Location);
            XpsDocument _xpsDocument = new XpsDocument(Location, FileAccess.ReadWrite);

            XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument);

            xpsdw.Write(fds);

            _xpsDocument.Close();
        }
Esempio n. 25
0
        public void FlowDocumentToPDF(DocumentPaginator paginator, string filename, string reportName, bool overWrite)
        {
            MemoryStream lMemoryStream = new MemoryStream();
            Package package = Package.Open(lMemoryStream, FileMode.Create);
            XpsDocument doc = new XpsDocument(package);

            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);

            XpsPackagingPolicy packagePolicy = new XpsPackagingPolicy(doc);
            XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, false);

            writer.Write(paginator);
            doc.Close();
            package.Close();

            var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(lMemoryStream);
            PdfSharp.Xps.XpsConverter.Convert(pdfXpsDoc, filename, 0);
            pdfXpsDoc.Close();
        }
Esempio n. 26
0
 public void SaveXpsDocument(string path, FlowDocument data)
 {
     var xpsDocument = new XpsDocument(path, FileAccess.ReadWrite, CompressionOption.Maximum);
     var writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
     var printTicket = new PrintTicket { PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4) };
     printTicket.PageResolution = new PageResolution(150, 150);
     Dispatcher.CurrentDispatcher.Invoke(DispatcherPriority.Loaded,
                                         new DispatcherOperationCallback(arg => null), null);
     writer.Write(((IDocumentPaginatorSource)data).DocumentPaginator, printTicket);
     xpsDocument.Close();
 }
Esempio n. 27
0
        public IEnumerable<Bitmap> ToBitmap(Parameters parameters)
        {
            var pages = new List<Bitmap>();
            var thread = new Thread(() =>
            {
                const string inMemoryPackageName = "memorystream://inmemory.xps";
                var packageUri = new Uri(inMemoryPackageName);
                using (var package = Package.Open(_xpsDocumentInMemoryStream))
                {
                    PackageStore.AddPackage(packageUri, package);

                    _xpsDocument = new XpsDocument(package, CompressionOption.Normal, inMemoryPackageName);
                    _xpsDocumentPaginator = _xpsDocument.GetFixedDocumentSequence().DocumentPaginator;

                    for (var docPageNumber = 0; docPageNumber < PageCount; docPageNumber++)
                    {
                        pages.Add(ProcessPage(parameters, docPageNumber));
                    }

                    PackageStore.RemovePackage(packageUri);

                    _xpsDocument.Close();
                    _xpsDocument = null;
                }
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.Start();
            thread.Join();
            return pages;
        }
        //private void SaveToPDF1_Click(object sender, RoutedEventArgs e)
        //{

        //    //try
        //    //{

        //    var a = this.ActualWidth;
        //    var b = this.ActualHeight;
        //    //TestPage fixedPage = new TestPage();
        //    // SaveToPDF.Visibility = Visibility.Collapsed;
        //    FixedDocument fixedDoc = new FixedDocument();
        //    PageContent pageContent = new PageContent();
        //    FixedPage fixedPage = new FixedPage();



        //    PrintDialog printDlg = new PrintDialog();

        //    //Size pageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight - 100);
        //    Size pageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight - 100);


        //    var visual = ((Panel)Content).Children[0] as UIElement;
        //    ((Panel)Content).Children.Remove(visual);
        //    fixedPage.Children.Add(visual);

        //    ((IAddChild)pageContent).AddChild(fixedPage);

        //    fixedDoc.Pages.Add(pageContent);

        //    // STEP 2: Convert this WPF Visual to an XPS Document
        //    MemoryStream lMemoryStream = new MemoryStream();
        //    {
        //        Package package = Package.Open(lMemoryStream, FileMode.Create);
        //        XpsDocument doc = new XpsDocument(package);
        //        XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);
        //        writer.Write(fixedDoc);
        //        doc.Close();
        //        package.Close();
        //    }

        //    // STEP 3: Convert this XPS Document to a PDF file
        //    MemoryStream lOutStream = new MemoryStream();
        //    NiXPS.Converter.XpsToPdf(lMemoryStream, lOutStream);
        //    File.WriteAllBytes(@"..\..\..\..\..\..\kinggty.pdf", lOutStream.ToArray());

        //    //if()
        //    //{



        //    //}
        //    //catch (Exception)
        //    //{
        //    //    MessageBox.Show("File Safe Unsucessfull \n Try Again", "ERROR MESSAGE");
        //    //}

        //}
        #endregion

        private void SaveToPDF_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new SaveFileDialog();

            //dialog.AddExtension = true;
            dialog.DefaultExt = "pdf";
            dialog.Filter     = "PDF Document (*.pdf)|*.pdf";

            if (dialog.ShowDialog() == false)
            {
                return;
            }
            #region Shrinks the uI Properly
            //align the page properly
            table1.Margin = new Thickness(-13, 116, 0, -16);
            //Height="647" Margin="-15,91,0,0"
            header1.Margin = new Thickness(7, 17, 12, 570);
            #endregion


            FixedDocument fixedDoc    = new FixedDocument();
            PageContent   pageContent = new PageContent();
            FixedPage     fixedPage   = new FixedPage();
            #region This Flips the Paper (A4 by standard ro be landscape)
            fixedPage.Width  = 11.6 * 96;
            fixedPage.Height = 8.27 * 96;
            #endregion


            //PrintDialog printDlg = new PrintDialog();
            //Size pageSize = new Size(printDlg.PrintableAreaWidth, printDlg.PrintableAreaHeight - 100);

            UIElement visual  = ((Panel)Content).Children[0] as UIElement;
            UIElement visual1 = ((Panel)Content).Children[1] as UIElement;

            ((Panel)Content).Children.Remove(visual);
            ((Panel)Content).Children.Remove(visual1);
            fixedPage.Children.Add(visual);
            fixedPage.Children.Add(visual1);

            ((IAddChild)pageContent).AddChild(fixedPage);

            fixedDoc.Pages.Add(pageContent);



            // write to PDF file
            string tempFilename = "temp.xps";
            File.Delete(tempFilename);
            XpsDocument       xpsd = new XpsDocument(tempFilename, FileAccess.Write);
            XpsDocumentWriter xw   = XpsDocument.CreateXpsDocumentWriter(xpsd);

            xw.Write(fixedDoc);

            xpsd.Close();
            try
            {
                XpsConverter.Convert(tempFilename, dialog.FileName, 1);
            }
            catch (Exception)
            {
                MessageBox.Show("File To be Replaced is used by Another Application \n Try Closing the File and Try Again");
            }
            finally
            {
                fixedPage.Children.Remove(visual);
                ((Panel)Content).Children.Add(visual);
                fixedPage.Children.Remove(visual1);
                ((Panel)Content).Children.Add(visual1);

                header1.Margin = new Thickness(4, -1, 15, 588);
                table1.Margin  = new Thickness(45, 81, 0, 0);
            }
        }
Esempio n. 29
0
        private void OnSaveFile(object sender, RoutedEventArgs e)
        {
            SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "XPS Document (*.XPS)|*.XPS|All Files (*.*)|*.*";
            if (saveDialog.ShowDialog() == true)
            {
                FixedDocument fixedDocument = new FixedDocument();
                fixedDocument.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11);

                // rest of the existing code
                PageContent firstPage = new PageContent();
                FixedPage fixedPage = new FixedPage();

                Canvas canvas = new Canvas();
                canvas.Width = fixedDocument.DocumentPaginator.PageSize.Width;
                canvas.Height = fixedDocument.DocumentPaginator.PageSize.Height;
                fixedPage.Children.Add(canvas);

                TextBlock tb = new TextBlock();
                tb.Foreground = Brushes.Black;
                tb.FontFamily = new System.Windows.Media.FontFamily("Arial");
                tb.FontSize = 36.0;
                tb.Text = "Hello";
                Canvas.SetTop(tb, 70);
                Canvas.SetLeft(tb, 70);
                canvas.Children.Add(tb);

                Ellipse ell = new Ellipse();
                ell.Width = 400;
                ell.Height = 400;
                ell.StrokeThickness = 3;
                ell.Stroke = new SolidColorBrush(Colors.Black);
                Canvas.SetTop(ell, 200);
                Canvas.SetLeft(ell, 300);
                canvas.Children.Add(ell);

                Border border = new Border();
                border.BorderBrush = Brushes.Black;
                border.BorderThickness = new Thickness(1);
                border.Width = (4 * 96);
                border.Height = (6 * 96);
                Canvas.SetLeft(border, 96);
                Canvas.SetTop(border, 3 * 96);
                canvas.Children.Add(border);

                FlowDocument docCopy = CopyFlowDocument(searchResults.Document);
                docCopy.ColumnWidth = double.NaN;
                docCopy.PageWidth = border.Width - 2;
                docCopy.PageHeight = border.Height - 2;
                IDocumentPaginatorSource paginatorSource = docCopy as IDocumentPaginatorSource;
                DocumentPage docPage = paginatorSource.DocumentPaginator.GetPage(0);

                VisualHolder holder = new VisualHolder();
                holder.Width = docCopy.PageWidth;
                holder.Height = docCopy.PageHeight;
                holder.HeldVisual = docPage.Visual;
                border.Child = holder;

                ((System.Windows.Markup.IAddChild)firstPage).AddChild(fixedPage);
                fixedDocument.Pages.Add(firstPage);

                XpsDocument doc = new XpsDocument(saveDialog.FileName, FileAccess.ReadWrite);

                XpsDocumentWriter docWriter = XpsDocument.CreateXpsDocumentWriter(doc);
                docWriter.Write(fixedDocument.DocumentPaginator);
                doc.Close();
            }
        }
Esempio n. 30
0
 public void Shutdown()
 {
     xpsDocument?.Close();
 }
        public void LoadXps()
        {
            //构造一个基于内存的xps document
            //MemoryStream ms = new MemoryStream();
            Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
            Uri DocumentUri = new Uri("pack://InMemoryDocument.xps");
            PackageStore.RemovePackage(DocumentUri);
            PackageStore.AddPackage(DocumentUri, package);
            XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.Fast, DocumentUri.AbsoluteUri);

            //将flow document写入基于内存的xps document中去
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
            if (this.isFixedPage)
            {
                writer.Write((FixedPage)m_doc);

            }
            else
            {
                writer.Write(((IDocumentPaginatorSource)m_doc).DocumentPaginator);
            }

            //获取这个基于内存的xps document的fixed document
            docViewer.Document = xpsDocument.GetFixedDocumentSequence();
            //关闭基于内存的xps document
            xpsDocument.Close();
        }
        /// <summary>
        /// Command handler for ExportXPSCommand
        /// </summary>
        private void ExportXps(object sender, EventArgs e)
        {
            CommonDialog dialog = new CommonDialog();
            dialog.InitialDirectory = People.ApplicationFolderPath;
            dialog.Filter.Add(new FilterEntry(Properties.Resources.XpsFiles, Properties.Resources.XpsExtension));
            dialog.Filter.Add(new FilterEntry(Properties.Resources.AllFiles, Properties.Resources.AllExtension));
            dialog.Title = Properties.Resources.Export;
            dialog.DefaultExtension = Properties.Resources.DefaultXpsExtension;
            dialog.ShowSave();

            if (!string.IsNullOrEmpty(dialog.FileName))
            {
                // Create the XPS document from the window's main container (in this case, a grid)
                Package package = Package.Open(dialog.FileName, FileMode.Create);
                XpsDocument xpsDoc = new XpsDocument(package);
                XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

                // Hide the zoom control before the diagram is saved
                DiagramControl.ZoomSliderPanel.Visibility = Visibility.Hidden;

                // Since DiagramBorder derives from FrameworkElement, the XpsDocument writer knows
                // how to output it's contents. The border is used instead of the DiagramControl
                // so that the diagram background is output as well as the digram control itself.
                xpsWriter.Write(DiagramBorder);
                xpsDoc.Close();
                package.Close();

                // Show the zoom control again
                DiagramControl.ZoomSliderPanel.Visibility = Visibility.Visible;
            }
        }
        public static void SaveXpsReportToTiff(string reportNo)
        {
            YellowstonePathology.Business.OrderIdParser orderIdParser = new YellowstonePathology.Business.OrderIdParser(reportNo);
            string inputFileName = YellowstonePathology.Business.Document.CaseDocument.GetCaseFileNameXPS(orderIdParser);
            string outputFileName = YellowstonePathology.Business.Document.CaseDocument.GetCaseFileNameTif(orderIdParser);

            if (File.Exists(inputFileName) == true)
            {
                XpsDocument xpsDoc = new XpsDocument(inputFileName, System.IO.FileAccess.Read);
                FixedDocumentSequence docSeq = xpsDoc.GetFixedDocumentSequence();
                int pages = docSeq.DocumentPaginator.PageCount;

                TiffBitmapEncoder encoder = new TiffBitmapEncoder();
                encoder.Compression = TiffCompressOption.Default;
                encoder.Compression = TiffCompressOption.Ccitt4;

                for (int pageNum = 0; pageNum < pages; pageNum++)
                {
                    DocumentPage docPage = docSeq.DocumentPaginator.GetPage(pageNum);
                    RenderTargetBitmap renderTarget =
                        new RenderTargetBitmap((int)(docPage.Size.Width * 300 / 96),
                                                (int)(docPage.Size.Height * 300 / 96),
                                                300d,
                                                300d,
                                                System.Windows.Media.PixelFormats.Default);

                    renderTarget.Render(docPage.Visual);
                    encoder.Frames.Add(BitmapFrame.Create(renderTarget));
                }

                FileStream pageOutStream = new FileStream(outputFileName, FileMode.Create, FileAccess.Write);
                encoder.Save(pageOutStream);
                pageOutStream.Close();

                xpsDoc.Close();
            }
        }
Esempio n. 34
-1
        public static void PrintPreview(Window owner, FormData data)
        {
            using (MemoryStream xpsStream = new MemoryStream())
            {
                using (Package package = Package.Open(xpsStream, FileMode.Create, FileAccess.ReadWrite))
                {
                    string packageUriString = "memorystream://data.xps";
                    Uri packageUri = new Uri(packageUriString);

                    PackageStore.AddPackage(packageUri, package);

                    XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.Maximum, packageUriString);
                    XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
                    Form visual = new Form(data);

                    PrintTicket printTicket = new PrintTicket();
                    printTicket.PageMediaSize = A4PaperSize;
                    writer.Write(visual, printTicket);
                    FixedDocumentSequence document = xpsDocument.GetFixedDocumentSequence();
                    xpsDocument.Close();

                    PrintPreviewWindow printPreviewWnd = new PrintPreviewWindow(document);
                    printPreviewWnd.Owner = owner;
                    printPreviewWnd.ShowDialog();
                    PackageStore.RemovePackage(packageUri);
                }
            }
        }