コード例 #1
0
 private void SaveToRTF(string filePath)
 {
     using (FileStream fileStream = new FileStream(filePath, FileMode.Create))
     {
         var flowDocument = Printing.CreateFlowDocumentToPrint(TextEditor);
         var textRange    = new TextRange(flowDocument.ContentStart, flowDocument.ContentEnd);
         textRange.Save(fileStream, DataFormats.Rtf);
     }
 }
コード例 #2
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);
                }
            }
        }
コード例 #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);
            }
        }