Exemplo n.º 1
0
        CreateAsyncSerializationManager(
            bool bBatchMode
            )
        {
            PackageSerializationManager serializationManager = null;

            XpsPackagingPolicy packagingPolicy = new XpsPackagingPolicy(this);

            serializationManager = new XpsSerializationManagerAsync(packagingPolicy, bBatchMode);

            return(serializationManager);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Actually print an Xps Document with previously setup params
        /// </summary>
        /// <param name="paginator">Document to print</param>
        /// <param name="description">Description</param>
        public void PrintDocument(DocumentPaginator paginator, string description)
        {
            if (paginator == null)
            {
                throw new ArgumentNullException("paginator", "No DocumentPaginator to print");
            }

            VerifyPrintSettings();

            //Handle XPS ourself, as their document writer hates our thread
            if (mPrintQueue.FullName.Contains("XPS"))
            {
                SaveFileDialog sfd = new SaveFileDialog();
                sfd.Filter = "Xps Document (*.xps) | *.xps";

                if (sfd.ShowDialog() == true)
                {
                    XpsDocument             document         = new XpsDocument(sfd.FileName, System.IO.FileAccess.Write);
                    XpsPackagingPolicy      packagePolicy    = new XpsPackagingPolicy(document);
                    XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, false);
                    serializationMgr.SaveAsXaml(paginator);

                    document.Close();
                }

                return;
            }

            XpsDocumentWriter writer = null;

            new PrintingPermission(PrintingPermissionLevel.DefaultPrinting).Assert();

            try
            {
                mPrintQueue.CurrentJobSettings.Description = description;
                writer = PrintQueue.CreateXpsDocumentWriter(mPrintQueue);

                TicketEventHandler handler = new TicketEventHandler(mPrintTicket);
                writer.WritingPrintTicketRequired += new WritingPrintTicketRequiredEventHandler(handler.SetPrintTicket);
            }
            finally
            {
                CodeAccessPermission.RevertAssert();
            }

            writer.Write(paginator);

            //Reset
            mPrintableWidth  = 0.0;
            mPrintableHeight = 0.0;
            mWidthUpdated    = false;
            mHeightUpdated   = false;
        }
Exemplo n.º 3
0
        CreateSerializationManager(
            bool bBatchMode
            )
        {
            PackageSerializationManager serializationManager = null;

            XpsPackagingPolicy packagingPolicy = new XpsPackagingPolicy(this);

            if (packagingPolicy != null)
            {
                serializationManager = new XpsSerializationManager(packagingPolicy, bBatchMode);
            }

            return(serializationManager);
        }
Exemplo n.º 4
0
    protected override void SaveCore(IDocument document, string fileName)
    {
        // We have to clone the FlowDocument before we use different pagination settings for the export.
        var richTextDocument = (RichTextDocument)document;
        var clone            = richTextDocument.CloneContent();

        clone.ColumnWidth = double.PositiveInfinity;

        using var package     = Package.Open(fileName, FileMode.Create);
        using var xpsDocument = new XpsDocument(package, CompressionOption.Maximum);
        using var policy      = new XpsPackagingPolicy(xpsDocument);
        using var serializer  = new XpsSerializationManager(policy, false);
        var paginator = ((IDocumentPaginatorSource)clone).DocumentPaginator;

        serializer.SaveAsXaml(paginator);
    }
Exemplo n.º 5
0
 private void SaveDocument([NotNull] IDocumentPaginatorSource document)
 {
     using (var package = Package.Open(_output, FileMode.Create, FileAccess.ReadWrite))
         using (var xps = new XpsDocument(package, CompressionOption.Maximum))
             using (var policy = new XpsPackagingPolicy(xps))
                 using (var serializer = new XpsSerializationManager(policy, false)) {
                     //document.DocumentPaginator.PageSize = new System.Windows.Size(100, 100);
                     serializer.SaveAsXaml(document.DocumentPaginator);
                     serializer.Commit();
                 }
     if (_leaveOpen)
     {
         _output.Flush();
     }
     else
     {
         _output.Dispose();
     }
 }
Exemplo n.º 6
0
    private void LoadedHandler(object sender, RoutedEventArgs e)
    {
        // We have to clone the FlowDocument before we use different pagination settings for the export.
        var clone = (FlowDocument)ViewModel.Document.CloneContent();

        clone.ColumnWidth = double.PositiveInfinity;

        var packageStream = new MemoryStream();

        package = Package.Open(packageStream, FileMode.Create, FileAccess.ReadWrite);
        PackageStore.AddPackage(new Uri(PackagePath), package);
        xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, PackagePath);
        using (var policy = new XpsPackagingPolicy(xpsDocument))
            using (var serializer = new XpsSerializationManager(policy, false))
            {
                var paginator = ((IDocumentPaginatorSource)clone).DocumentPaginator;
                serializer.SaveAsXaml(paginator);
            }
        documentViewer.Document = xpsDocument.GetFixedDocumentSequence();
        documentViewer.Focus();
    }
Exemplo n.º 7
0
        void printButton_Click(object sender, RoutedEventArgs e)
        {
            Frame itemToPrint = GetCurrentFrame();

            // do printing here...
            string path = string.Format(@"c:\temp\{0}.xps", itemToPrint.Source.ToString().Replace("/", "."));;

            if (File.Exists(path))
            {
                File.Delete(path);
            }

            using (XpsDocument doc = new XpsDocument(path, System.IO.FileAccess.ReadWrite))
            {
                XpsPackagingPolicy      packagePolicy    = new XpsPackagingPolicy(doc);
                XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, false);

                serializationMgr.SaveAsXaml(itemToPrint); // this can be any UI element
            }

            System.Diagnostics.Process.Start(path);
        }
Exemplo n.º 8
0
        public void FlowDocumentToXps(DocumentPaginator paginator, string filename, string reportName, bool overWrite)
        {
            XpsDocument document;

            if (overWrite)
            {
                document = new XpsDocument(filename, FileAccess.Write);
            }
            else
            {
                document = new XpsDocument(filename, FileAccess.ReadWrite);
            }

            XpsPackagingPolicy packagePolicy = new XpsPackagingPolicy(document);

            XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, true);

            serializationMgr.Commit();

            serializationMgr.SaveAsXaml(paginator);


            document.Close();
        }
Exemplo n.º 9
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();
        }
Exemplo n.º 10
0
        public void FlowDocumentToXps(DocumentPaginator paginator, string filename, string reportName, bool overWrite)
        {
            XpsDocument document;
            if (overWrite)
                document = new XpsDocument(filename, FileAccess.Write);
            else
                document = new XpsDocument(filename, FileAccess.ReadWrite);

            XpsPackagingPolicy packagePolicy = new XpsPackagingPolicy(document);

            XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, true);

            serializationMgr.Commit();

            serializationMgr.SaveAsXaml(paginator);

            document.Close();
        }
Exemplo n.º 11
0
 internal PackageSerializationManager CreateSerializationManager(bool bBatchMode)
 {
     PackageSerializationManager manager = null;
     XpsPackagingPolicy packagingPolicy = new XpsPackagingPolicy(this);
     if (packagingPolicy != null)
     {
         manager = new XpsSerializationManager(packagingPolicy, bBatchMode);
     }
     return manager;
 }
Exemplo n.º 12
0
		/// <summary>
		/// Actually print an Xps Document with previously setup params
		/// </summary>
		/// <param name="paginator">Document to print</param>
		/// <param name="description">Description</param>
		public void PrintDocument(DocumentPaginator paginator, string description)
		{
			if (paginator == null)
				throw new ArgumentNullException("paginator", "No DocumentPaginator to print");

			VerifyPrintSettings();

			//Handle XPS ourself, as their document writer hates our thread
			if (mPrintQueue.FullName.Contains("XPS"))
			{
				SaveFileDialog sfd = new SaveFileDialog();
				sfd.Filter = "Xps Document (*.xps) | *.xps";

				if (sfd.ShowDialog() == true)
				{
					XpsDocument document = new XpsDocument(sfd.FileName, System.IO.FileAccess.Write);
					XpsPackagingPolicy packagePolicy = new XpsPackagingPolicy(document);
					XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, false);
					serializationMgr.SaveAsXaml(paginator);

					document.Close();
				}

				return;
			}

			XpsDocumentWriter writer = null;
			new PrintingPermission(PrintingPermissionLevel.DefaultPrinting).Assert();

			try
			{
				mPrintQueue.CurrentJobSettings.Description = description;
				writer = PrintQueue.CreateXpsDocumentWriter(mPrintQueue);

				TicketEventHandler handler = new TicketEventHandler(mPrintTicket);
				writer.WritingPrintTicketRequired += new WritingPrintTicketRequiredEventHandler(handler.SetPrintTicket);
			}
			finally
			{
				CodeAccessPermission.RevertAssert();
			}

			writer.Write(paginator);

			//Reset
			mPrintableWidth = 0.0;
			mPrintableHeight = 0.0;
			mWidthUpdated = false;
			mHeightUpdated = false;
		}