Ejemplo n.º 1
0
        public static void SaveDocument(RadFlowDocument document, string selectedFromat)
        {
            IFormatProvider<RadFlowDocument> formatProvider = null;
            switch (selectedFromat)
            {
                case "Docx":
                    formatProvider = new DocxFormatProvider();
                    break;
                case "Rtf":
                    formatProvider = new RtfFormatProvider();
                    break;
                case "Txt":
                    formatProvider = new TxtFormatProvider();
                    break;
            }
            if (formatProvider == null)
            {
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();
            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                selectedFromat,
                formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get Supported providers for the import operation based on the file extension
        /// </summary>
        /// <param name="extension">the extension of the file we will import, used to discern the provider type</param>
        /// <returns>IFormatProvider<RadFlowDocument> that you can use to read that file and import it as an in-memory document you can convert to other formats</returns>
        IFormatProvider <RadFlowDocument> GetImportFormatProvider(string extension)
        {
            IFormatProvider <RadFlowDocument> fileFormatProvider;

            switch (extension)
            {
            case ".docx":
                fileFormatProvider = new DocxFormatProvider();
                break;

            case ".rtf":
                fileFormatProvider = new RtfFormatProvider();
                break;

            case ".html":
                fileFormatProvider = new HtmlFormatProvider();
                break;

            case ".txt":
                fileFormatProvider = new TxtFormatProvider();
                break;

            default:
                fileFormatProvider = null;
                break;
            }

            if (fileFormatProvider == null)
            {
                throw new NotSupportedException("The chosen file cannot be read with the supported providers.");
            }

            return(fileFormatProvider);
        }
Ejemplo n.º 3
0
 private void ImportFromString(string input)
 {
     #region radwordsprocessing-formats-and-conversion-rtf-rtfformatprovider_1
     RtfFormatProvider provider = new RtfFormatProvider();
     RadFlowDocument   document = provider.Import(input);
     #endregion
 }
Ejemplo n.º 4
0
 private void ExportToArray()
 {
     #region radwordsprocessing-formats-and-conversion-rtf-rtfformatprovider_3
     RtfFormatProvider provider = new RtfFormatProvider();
     RadFlowDocument   document = CreateRadFlowDocument();
     string            output   = provider.Export(document);
     #endregion
 }
        private void Validate_Click(object sender, RoutedEventArgs e)
        {
            RtfFormatProvider rtf = new RtfFormatProvider();

            _viewModel.Validate(Id.Text, NameField.Text, rtf.Export(TextEditor.Document), PrevMXEU.Text, PrevMXEUM.Text, PrevMXEM.Text, PrevMXUSLC.Text, place);
            validated = true;
            this.Close();
        }
Ejemplo n.º 6
0
 private void AppkyExportSettings()
 {
     #region radwordsprocessing-formats-and-conversion-rtf-settings_0
     RtfFormatProvider provider       = new RtfFormatProvider();
     RtfExportSettings exportSettings = new RtfExportSettings();
     exportSettings.ExportImagesInCompatibilityMode = true;
     provider.ExportSettings = exportSettings;
     #endregion
 }
Ejemplo n.º 7
0
        private void Save(string format)
        {
            if (this.document == null)
            {
                Console.WriteLine("Cannot save. A document is not loaded.");
                return;
            }

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (format)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }

            if (formatProvider == null)
            {
                Console.WriteLine("Not supported document format.");
                return;
            }

            string path = "Converted." + format;

            using (FileStream stream = File.OpenWrite(path))
            {
                formatProvider.Export(this.document, stream);
            }

            Console.WriteLine("Document converted.");

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = path,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
Ejemplo n.º 8
0
 private void ImportFromFile()
 {
     #region radwordsprocessing-formats-and-conversion-rtf-rtfformatprovider_0
     RtfFormatProvider provider = new RtfFormatProvider();
     using (Stream input = File.OpenRead("Sample.rtf"))
     {
         RadFlowDocument document = provider.Import(input);
     }
     #endregion
 }
Ejemplo n.º 9
0
        void EmailBodyContent_DataContextChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            var mimePartVm = e.NewValue as MimePartVm;

            if (mimePartVm != null)
            {
                RadDocument content = null;
                var         plain   = true;
                if (!String.IsNullOrEmpty(mimePartVm.MIMEpart.ContentSubtype))
                {
                    if (mimePartVm.MIMEpart.ContentSubtype.Equals("html"))
                    {
                        content = new HtmlFormatProvider().Import(mimePartVm.RawContent);
                        plain   = false;
                    }
                    else if (mimePartVm.MIMEpart.ContentSubtype.Equals("rtf"))
                    {
                        content = new RtfFormatProvider().Import(mimePartVm.RawContent);
                        plain   = false;
                    }

                    /* else if (mimePartVm.Data.ContentSubtype.Equals("pdf"))
                     * {
                     *   content = new PdfFormatProvider().Import(mimePartVm.RawContent);
                     * }*/
                    else
                    {
                        content = new TxtFormatProvider().Import(mimePartVm.RawContent);
                        //content = new XamlFormatProvider().Import(mimePartVm.RawContent);
                    }
                }
                else
                {
                    // content = new XamlFormatProvider().Import(mimePartVm.RawContent);
                    //TxtFormatProvider formatProvider = new TxtFormatProvider();
                    content = new TxtFormatProvider().Import(mimePartVm.RawContent);
                    //content = new TxtDataProvider(mimePartVm.RawContent);
                }

                if (plain)
                {
                    foreach (var span in content.EnumerateChildrenOfType <Span>())
                    {
                        span.FontSize = 12;
                    }
                }

                content.LineSpacing = 1.1;
                content.ParagraphDefaultSpacingAfter  = 0;
                content.ParagraphDefaultSpacingBefore = 0;

                this.ContentTextBox.LineBreakingRuleLanguage = LineBreakingRuleLanguage.None;
                this.ContentTextBox.Document = content;
            }
        }
Ejemplo n.º 10
0
 private void ExportToFile()
 {
     #region radwordsprocessing-formats-and-conversion-rtf-rtfformatprovider_2
     RtfFormatProvider provider = new RtfFormatProvider();
     using (Stream output = File.Create("sample.rtf"))
     {
         RadFlowDocument document = CreateRadFlowDocument();
         provider.Export(document, output);
     }
     #endregion
 }
        private void SaveDocument(RadFlowDocument document, string selectedFormat)
        {
            string selectedFormatLower = selectedFormat.ToLower();

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (selectedFormatLower)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }

            if (formatProvider == null)
            {
                Console.WriteLine("Uknown or not supported format.");
                return;
            }

            string path = "Sample document." + selectedFormat;

            using (FileStream stream = File.OpenWrite(path))
            {
                formatProvider.Export(document, stream);
            }

            Console.Write("Document generated.");

            ProcessStartInfo psi = new ProcessStartInfo()
            {
                FileName        = path,
                UseShellExecute = true
            };

            Process.Start(psi);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Get Supported providers for the export operation based on the file name, also gets its MIME type as an out parameter
        /// </summary>
        /// <param name="fileName">the file name you wish to export, the provider is discerned based on its extensiom</param>
        /// <param name="mimeType">an out parameter with the MIME type for this file so you can download it</param>
        /// <returns>IFormatProvider<RadFlowDocument> that you can use to export the original document to a certain file format</returns>
        IFormatProvider <RadFlowDocument> GetExportFormatProvider(string fileName, out string mimeType)
        {
            // we get both the provider and the MIME type to use only one swtich-case
            IFormatProvider <RadFlowDocument> fileFormatProvider;
            string extension = Path.GetExtension(fileName);

            switch (extension)
            {
            case ".docx":
                fileFormatProvider = new DocxFormatProvider();
                mimeType           = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
                break;

            case ".rtf":
                fileFormatProvider = new RtfFormatProvider();
                mimeType           = "application/rtf";
                break;

            case ".html":
                fileFormatProvider = new HtmlFormatProvider();
                mimeType           = "text/html";
                break;

            case ".txt":
                fileFormatProvider = new TxtFormatProvider();
                mimeType           = "text/plain";
                break;

            case ".pdf":
                fileFormatProvider = new pdfProviderNamespace.PdfFormatProvider();
                mimeType           = "application/pdf";
                break;

            default:
                fileFormatProvider = null;
                mimeType           = string.Empty;
                break;
            }

            if (fileFormatProvider == null)
            {
                throw new NotSupportedException("The chosen format cannot be exported with the supported providers.");
            }

            return(fileFormatProvider);
        }
Ejemplo n.º 13
0
        public void Writecoment(DataRow row)
        {
            if (row == null)
            {
                return;
            }

            String            id      = row["id_comment"].ToString();
            RtfFormatProvider rtf     = new RtfFormatProvider();
            String            comment = _viewModel.FillRecoTextBox(id).ToString();

            if (comment == "")
            {
                CommentReader.Document = new RadDocument();
                return;
            }
            CommentReader.Document = rtf.Import(comment);
        }
Ejemplo n.º 14
0
        private void Save(string format)
        {
            if (this.document == null)
            {
                Console.WriteLine("Cannot save. A document is not loaded.");
                return;
            }

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (format)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }
            if (formatProvider == null)
            {
                Console.WriteLine("Not supported document format.");
                return;
            }

            using (var stream = File.OpenWrite("Converted." + format))
            {
                formatProvider.Export(this.document, stream);
                Console.WriteLine("The document is converted and saved.");
            }
        }
Ejemplo n.º 15
0
        private void SaveDocument(RadFlowDocument document, string selectedFormat)
        {
            string selectedFormatLower = selectedFormat.ToLower();

            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (selectedFormatLower)
            {
            case "docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "txt":
                formatProvider = new TxtFormatProvider();
                break;

            case "html":
                formatProvider = new HtmlFormatProvider();
                break;

            case "pdf":
                formatProvider = new PdfFormatProvider();
                break;
            }

            if (formatProvider == null)
            {
                Console.WriteLine("Uknown or not supported format!");
                return;
            }

            using (var stream = File.OpenWrite("Sample document." + selectedFormat))
            {
                Console.WriteLine("Exporting to {0}...", selectedFormat);
                formatProvider.Export(document, stream);
                Console.WriteLine("Done.");
            }
        }
Ejemplo n.º 16
0
        public static void SaveDocument(RadFlowDocument document, string selectedFromat)
        {
            IFormatProvider <RadFlowDocument> formatProvider = null;

            switch (selectedFromat)
            {
            case "Docx":
                formatProvider = new DocxFormatProvider();
                break;

            case "Rtf":
                formatProvider = new RtfFormatProvider();
                break;

            case "Txt":
                formatProvider = new TxtFormatProvider();
                break;
            }
            if (formatProvider == null)
            {
                return;
            }

            SaveFileDialog dialog = new SaveFileDialog();

            dialog.Filter = String.Format("{0} files|*{1}|All files (*.*)|*.*",
                                          selectedFromat,
                                          formatProvider.SupportedExtensions.First());
            dialog.FilterIndex = 1;

            if (dialog.ShowDialog() == true)
            {
                using (var stream = dialog.OpenFile())
                {
                    formatProvider.Export(document, stream);
                }
            }
        }
Ejemplo n.º 17
0
        private async Task Generate()
        {
            RadFlowDocument document = this.CreateDocument();
            IFormatProvider <RadFlowDocument> formatProvider = null;
            string exampleName = null;

            switch (selectedExportFormat)
            {
            case "Docx":
                formatProvider = new DocxFormatProvider();
                exampleName    = "example.docx";
                break;

            case "Rtf":
                formatProvider = new RtfFormatProvider();
                exampleName    = "example.rtf";
                break;

            case "Html":
                formatProvider = new HtmlFormatProvider();
                exampleName    = "example.html";
                break;

            case "Txt":
                formatProvider = new TxtFormatProvider();
                exampleName    = "example.txt";
                break;
            }

            using (MemoryStream stream = new MemoryStream())
            {
                formatProvider.Export(document, stream);

                stream.Seek(0, SeekOrigin.Begin);

                await this.fileViewerService.View(stream, exampleName);
            }
        }
Ejemplo n.º 18
0
        private async void ExportCommandExecute()
        {
            this.OpenSample();

            IFormatProvider <RadFlowDocument> formatProvider = null;
            string exampleName = null;

            switch (this.selectedExportFormat)
            {
            case "PDF files(*.pdf)":
                formatProvider = new PdfFormatProvider();
                exampleName    = "example.pdf";
                break;

            case "RTF files(*.rtf)":
                formatProvider = new RtfFormatProvider();
                exampleName    = "example.rtf";
                break;

            case "HTML files(*.html)":
                formatProvider = new HtmlFormatProvider();
                exampleName    = "example.html";
                break;

            case "TXT files(*.txt)":
                formatProvider = new TxtFormatProvider();
                exampleName    = "example.txt";
                break;
            }

            using (MemoryStream stream = new MemoryStream())
            {
                formatProvider.Export(this.flowDocument, stream);
                stream.Seek(0, SeekOrigin.Begin);
                await this.fileViewerService.View(stream, exampleName);
            }
        }