Ejemplo n.º 1
0
        private void SaveAsXps(TextEditor textEditor, string fileName, string title)
        {
            using (Package package = Package.Open(fileName, FileMode.Create))
            {
                using (XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Fast))
                {
                    XpsSerializationManager  xpsSerializationManager = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);
                    DocumentPaginatorWrapper paginator = Printing.CreateDocumentPaginatorToPrint(textEditor);
                    paginator.Title = title;

                    xpsSerializationManager.SaveAsXaml(paginator);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a DocumentPaginatorWrapper from TextEditor text to print.
        /// </summary>
        public static DocumentPaginatorWrapper CreateDocumentPaginatorToPrint(TextEditor textEditor)
        {
            PrintSettings settings = textEditor.Tag as PrintSettings;

            if (settings == null)
            {
                settings       = new PrintSettings();
                textEditor.Tag = settings;
            }

            // this baby adds headers and footers
            IDocumentPaginatorSource dps = CreateFlowDocumentToPrint(textEditor);
            DocumentPaginatorWrapper dpw = new DocumentPaginatorWrapper(dps.DocumentPaginator, settings.PageSettings, settings.PrintTicket, textEditor.FontFamily);

            dpw.Title = settings.DocumentTitle;
            return(dpw);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create PDF file by using PdfSharp. It create a InMemory XPS file internally,
        /// then convert the XPS stream to PDF file.
        /// </summary>
        /// <param name="pdfFilePath"></param>
        private void SaveAsPDFBySharpPDF(string pdfFilePath)
        {
            using (MemoryStream xpsStream = new MemoryStream())
            {
                Package           package        = Package.Open(xpsStream, FileMode.Create);
                XpsDocument       xpsDocInMemory = new XpsDocument(package);
                XpsDocumentWriter writer         = XpsDocument.CreateXpsDocumentWriter(xpsDocInMemory);

                DocumentPaginatorWrapper paginator = Printing.CreateDocumentPaginatorToPrint(TextEditor);
                paginator.Title = FilePath2Title(pdfFilePath);

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

                var xpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(xpsStream);
                PdfSharp.Xps.XpsConverter.Convert(xpsDoc, pdfFilePath, 0);
            }
        }