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); } } }
private void LoadDocumentation() { try { var document = new DocxFormatProvider().Import(LocalizedResources.StringFormatDocumentation); _richTextBox = new RadRichTextBox { HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled, LayoutMode = DocumentLayoutMode.Flow, IsSpellCheckingEnabled = false, IsContextMenuEnabled = false, IsImageMiniToolBarEnabled = false, IsSelectionMiniToolBarEnabled = false, IsSelectionEnabled = false, IsTabStop = false, IsReadOnly = true, Padding = new Thickness(20, 20, 20, 0), Background = new SolidColorBrush(Colors.White), BorderThickness = new Thickness(0), MouseOverBorderThickness = new Thickness(0), Document = document }; ContentControl.Content = _richTextBox; } catch (Exception ex) { Logger.Log(LogSeverity.Error, "FormatStringDocumentationView", ex); DocumentationPlaceholder.Text = LanguageService.Translate("Error_LoadFormatStringDescriptionFailed"); } }
/// <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); }
private void ImportFromByteArray(byte[] input) { #region radwordsprocessing-formats-and-conversion-docx-docxformatprovider_1 DocxFormatProvider provider = new DocxFormatProvider(); RadFlowDocument document = provider.Import(input); #endregion }
private void SaveFile(RadFlowDocument document) { using (Stream stream = File.OpenWrite("Mail Merge Sample.docx")) { DocxFormatProvider formatProvder = new DocxFormatProvider(); formatProvder.Export(document, stream); } }
private void ExportToWord() { RadDocument document = GenerateRadDocument(); var provider = new DocxFormatProvider(); ShowPrintPreviewDialog(document, provider); }
private RadFlowDocument OpenSample() { using (Stream stream = File.OpenRead(TemplatePath)) { DocxFormatProvider docxFormatProvider = new DocxFormatProvider(); return(docxFormatProvider.Import(stream)); } }
private void LoadSampleDocument() { Stream stream = Application.GetResourceStream(new Uri(SampleDocumentPath, UriKind.RelativeOrAbsolute)).Stream; DocxFormatProvider provider = new DocxFormatProvider(); RadDocument document = provider.Import(stream); this.radRichTextBox.Document = document; }
private void RadRichTextBox_Loaded(object sender, RoutedEventArgs e) { using (Stream stream = Application.GetResourceStream(GetResourceUri(SampleDocumentPath)).Stream) { DocxFormatProvider provider = new DocxFormatProvider(); this.radRichTextBox.Document = provider.Import(stream); } }
protected override void WriteToFile() { using (var wordStream = File.Open(OutputFileLocation, FileMode.Create)) { var docxFormatProvider = new DocxFormatProvider(); docxFormatProvider.Export(Document, wordStream); } }
private void ExportToArray() { #region radwordsprocessing-formats-and-conversion-docx-docxformatprovider_3 DocxFormatProvider provider = new DocxFormatProvider(); RadFlowDocument document = CreateRadFlowDocument(); byte[] output = provider.Export(document); #endregion }
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); }
private void ImportFromFile() { #region radwordsprocessing-formats-and-conversion-docx-docxformatprovider_0 DocxFormatProvider provider = new DocxFormatProvider(); using (Stream input = File.OpenRead("Sample.docx")) { RadFlowDocument document = provider.Import(input); } #endregion }
public ReportGenerator(string oTemplatePath) { DocxFormatProvider provider = new DocxFormatProvider(); using (Stream input = File.OpenRead(oTemplatePath)) { m_Document = provider.Import(input); m_Editor = new RadFlowDocumentEditor(new RadFlowDocument()); } }
private void AppkyExportSettings() { #region radwordsprocessing-formats-and-conversion-docx-settings_0 DocxFormatProvider provider = new DocxFormatProvider(); DocxExportSettings exportSettings = new DocxExportSettings(); exportSettings.AutoUpdateFields = true; exportSettings.InvalidDocumentAction = InvalidDocumentAction.ThrowException; provider.ExportSettings = exportSettings; #endregion }
private void ExportToDocx(RadFlowDocument document) { #region radwordsprocessing-getting-started_1 using (Stream output = new FileStream("output.docx", FileMode.OpenOrCreate)) { DocxFormatProvider provider = new DocxFormatProvider(); provider.Export(document, output); } #endregion }
protected RadFlowDocument LoadSampleDocument() { RadFlowDocument document2; IFormatProvider <RadFlowDocument> fileFormatProvider = new DocxFormatProvider(); string fileName = Server.MapPath(templatesFolder + "ΤΙΜ ΕΛΛ 1212 598.docx"); using (FileStream input = new FileStream(fileName, FileMode.Open)) { document2 = fileFormatProvider.Import(input); } return(document2); }
private void ExportToFile() { #region radwordsprocessing-formats-and-conversion-docx-docxformatprovider_2 DocxFormatProvider provider = new DocxFormatProvider(); using (Stream output = File.OpenWrite("Sample.docx")) { RadFlowDocument document = CreateRadFlowDocument(); provider.Export(document, output); } #endregion }
public CreateClientLetterTelerik(CashFlowInformation information, int cashFlowNumber, IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; this.information = information; this.cashFlowNumber = cashFlowNumber; provider = new DocxFormatProvider(); ReplaceWordContent(information); }
public CreateClientLetterTelerik(string sourcePath, string saveAsFile, CashFlowInformation information, CashFlowDetail detail) { this.sourcePath = sourcePath; SaveAsFile = saveAsFile; this.information = information; this.detail = detail; FillStrings(detail); RadFlowDocument wordDocument = new RadFlowDocument(); provider = new DocxFormatProvider(); try { using (Stream input = File.OpenRead(sourcePath)) { wordDocument = provider.Import(input); } } catch (Exception ex) { throw new Exception($"Das Word-Template konnte nicht geöffnet werden. {ex.Message}"); } editor = new RadFlowDocumentEditor(wordDocument); ReplacePlaceholder(detail); int pos = saveAsFile.LastIndexOf("."); string fileName = saveAsFile.Substring(0, pos) + ".docx"; using (Stream output = File.OpenWrite(fileName)) { provider.Export(editor.Document, output); } string pdfFile = fileName.Replace(".docx", ".pdf"); // cpmversion of a flowdocument to a fixeddocument PdfFormatProvider pdfProvider = new PdfFormatProvider(); RadFixedDocument fixedDocument = pdfProvider.ExportToFixedDocument(editor.Document); // write the fixeddocuement to file Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider fixedProvider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider(); using (Stream output = File.OpenWrite(pdfFile)) { fixedProvider.Export(fixedDocument, output); } }
private void OpenWord(string fileName) { var provider = new DocxFormatProvider(); using (Stream input = File.OpenRead(fileName)) { m_Document = provider.Import(input); } m_Filename = fileName; Text = "Calendar Converter - " + fileName; }
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); }
private void SaveFile(RadFlowDocument document) { string path = "Mail Merge Sample.docx"; using (Stream stream = File.OpenWrite(path)) { DocxFormatProvider formatProvder = new DocxFormatProvider(); formatProvder.Export(document, stream); } Process.Start(path); Console.Write("Mail merge finished - the document is saved."); }
public ActionResult ExportDocx(string content) { HtmlFormatProvider htmlProvider = new HtmlFormatProvider(); RadFlowDocument htmlDocument = htmlProvider.Import(content); DocxFormatProvider docxProvider = new DocxFormatProvider(); using (Stream output = System.IO.File.OpenWrite(Server.MapPath("~/App_Data/Sample.docx"))) { docxProvider.Export(htmlDocument, output); } return(new HttpStatusCodeResult(HttpStatusCode.OK)); }
private RadFlowDocument OpenSample() { Assembly assembly = typeof(FindAndReplaceView).Assembly; string fileName = assembly.GetManifestResourceNames().FirstOrDefault(n => n.Contains("JohnGrisham.docx")); RadFlowDocument doc = new RadFlowDocument(); using (Stream stream = assembly.GetManifestResourceStream(fileName)) { doc = new DocxFormatProvider().Import(stream); } return(doc); }
private void SaveFile(RadFlowDocument document) { SaveFileDialog dialog = new SaveFileDialog(); dialog.Filter = "Docx File (*.docx)|*.docx"; if (dialog.ShowDialog() == true) { using (Stream stream = dialog.OpenFile()) { DocxFormatProvider formatProvder = new DocxFormatProvider(); formatProvder.Export(document, stream); } } }
private void btnPrint_Click(object sender, EventArgs e) { IDocumentFormatProvider provider = new DocxFormatProvider(); using (Stream output = (Stream)File.Open("print.docx", FileMode.Create)) { provider.Export(this.docCertificate.Document, output); } try { ProcessStartInfo info = new ProcessStartInfo("print.docx"); info.Verb = "PrintTo"; info.CreateNoWindow = true; info.ErrorDialog = false; info.WindowStyle = ProcessWindowStyle.Hidden; Process.Start(info); } catch { } }
protected void exportDOCX(RadFlowDocument doc) { IFormatProvider <RadFlowDocument> formatProvider = new DocxFormatProvider(); byte[] renderedBytes = null; using (MemoryStream ms = new MemoryStream()) { formatProvider.Export(doc, ms); renderedBytes = ms.ToArray(); } Response.ClearHeaders(); Response.ClearContent(); Response.AppendHeader("content-disposition", "attachment; filename=ExportedFile.docx"); Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; Response.BinaryWrite(renderedBytes); Response.End(); }
private void Initialize() { InitializeComponent(); RadMenuInsertTableItem insertTableBoxItem = new RadMenuInsertTableItem(); this.radDropDownButtonElementTables.Items.Insert(0, insertTableBoxItem); insertTableBoxItem.SelectionChanged += new EventHandler <TableSelectionChangedEventArgs>(OnInsertTableSelectionChanged); this.radMenuItemInsertTable.Click += new EventHandler(radMenuItemInsertTable_Click); ThemeResolutionService.ApplicationThemeName = "Office2010Blue"; this.radRibbonBar1.RibbonBarElement.ApplicationButtonElement.Text = "File"; this.radRibbonBar1.RibbonBarElement.ApplicationButtonElement.ForeColor = Color.White; this.radRibbonBar1.RibbonBarElement.ApplicationButtonElement.DisplayStyle = DisplayStyle.Text; this.radDropDownListFontSize.DropDownStyle = RadDropDownStyle.DropDownList; this.radDropDownListFont.DropDownStyle = RadDropDownStyle.DropDownList; this.radPageView1.SelectedPage = this.radPageViewPageSaveAsWord; DocxFormatProvider docxProvider = new DocxFormatProvider(); RadDocument document = docxProvider.Import(Resources.RichTextBox_for_WinForms); this.AttachDocument(document); this.radRichTextBox1.Document = document; this.radBtnPrintLayout.ToggleState = ToggleState.On; this.radRichTextBox1.CurrentEditingStyleChanged += new EventHandler(radRichTextBox1_CurrentEditingStyleChanged); this.radPageViewPageSaveAsHtml.Item.Click += new EventHandler(this.radBtnSave_Click); this.radPageViewPageSaveAsPDF.Item.Click += new EventHandler(this.radBtnSave_Click); this.radPageViewPageSaveAsRTF.Item.Click += new EventHandler(this.radBtnSave_Click); this.radPageViewPageSaveAsText.Item.Click += new EventHandler(this.radBtnSave_Click); this.radPageViewPageSaveAsWord.Item.Click += new EventHandler(this.radBtnSave_Click); this.radPageViewPageSaveAsXAML.Item.Click += new EventHandler(this.radBtnSave_Click); this.radDropDownListFont.DropDownAnimationEnabled = false; this.radDropDownListFontSize.DropDownAnimationEnabled = false; AttachSignal(); this.closeTimer = new System.Windows.Forms.Timer(); this.closeTimer.Interval = 3000; this.closeTimer.Tick += new EventHandler(closeTimer_Tick); this.closeTimer.Start(); }
/// <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); }
private async void GenerateSampleExecute() { if (this.sampleDocument == null) { this.sampleDocument = this.OpenSample(); } IFormatProvider <RadFlowDocument> formatProvider = new DocxFormatProvider(); string exampleName = "example.docx"; using (MemoryStream stream = new MemoryStream()) { formatProvider.Export(this.sampleDocument, stream); stream.Seek(0, SeekOrigin.Begin); await this.fileViewerService.View(stream, exampleName); } }
//Save File public void ExportToDocx(RadDocument document) { DocxFormatProvider provider = new DocxFormatProvider(); SaveFileDialog saveDialog = new SaveFileDialog(); saveDialog.DefaultExt = ".hcx"; saveDialog.Filter = "Documents|*.hcx"; DialogResult dialogResult = saveDialog.ShowDialog(); if (dialogResult == System.Windows.Forms.DialogResult.OK) { using (Stream output = saveDialog.OpenFile()) { provider.Export(document, output); MessageBox.Show("Saved Successfuly!"); } } }
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."); } }
public ActionResult ImportDocx() { RadFlowDocument flowDocument; DocxFormatProvider docxProvider = new DocxFormatProvider(); using (Stream input = System.IO.File.OpenRead(Server.MapPath("~/App_Data/Sample.docx"))) { flowDocument = docxProvider.Import(input); } HtmlFormatProvider htmlProvider = new HtmlFormatProvider(); htmlProvider.ExportSettings.DocumentExportLevel = DocumentExportLevel.Fragment; htmlProvider.ExportSettings.StylesExportMode = StylesExportMode.Inline; string html = htmlProvider.Export(flowDocument); return(Content(html)); }
public static void Export(this RadGridView grid, ExportSettings settings) { var dialog = new SaveFileDialog(); switch (settings.Format) { case ExportFormat.Pdf: dialog.DefaultExt = "*.pdf"; dialog.Filter = "Adobe PDF 文档 (*.pdf)|*.pdf"; break; case ExportFormat.Excel: dialog.DefaultExt = "*.xlsx"; dialog.Filter = "Excel 工作簿 (*.xlsx)|*.xlsx"; break; case ExportFormat.Word: dialog.DefaultExt = "*.docx"; dialog.Filter = "Word 文档 (*.docx)|*.docx"; break; case ExportFormat.Csv: dialog.DefaultExt = "*.csv"; dialog.Filter = "CSV (逗号分隔) (*.csv)|*.csv"; break; } if (settings.FileName != null) { dialog.DefaultFileName = settings.FileName; } if (dialog.ShowDialog() == true) { switch (settings.Format) { case ExportFormat.Csv: using (var output = dialog.OpenFile()) { grid.Export(output, new GridViewExportOptions { Format = Telerik.Windows.Controls.ExportFormat.Csv, ShowColumnFooters = grid.ShowColumnFooters, ShowColumnHeaders = grid.ShowColumnHeaders, ShowGroupFooters = grid.ShowGroupFooters }); } break; case ExportFormat.Excel: { var workbook = CreateWorkBook(grid); if (workbook != null) { var provider = new XlsxFormatProvider(); using (var output = dialog.OpenFile()) { provider.Export(workbook, output); } } } break; default: { var document = CreateDocument(grid, settings); if (document != null) { document.LayoutMode = DocumentLayoutMode.Paged; document.Measure(RadDocument.MAX_DOCUMENT_SIZE); document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize)); IDocumentFormatProvider provider = null; switch (settings.Format) { case ExportFormat.Pdf: provider = new PdfFormatProvider(); break; case ExportFormat.Word: provider = new DocxFormatProvider(); break; } using (var output = dialog.OpenFile()) { if (provider != null) provider.Export(document, output); } } } break; } } }
public DocFormatProvider() { this.docxProvider = new DocxFormatProvider(); }