// Saving Invoice at DataBase public void InvoiceSave() { MemoryStream rtfStream = new MemoryStream(); MemoryStream pdfStream = new MemoryStream(); ASPxRichEdit1.SaveCopy(rtfStream, DocumentFormat.Rtf); ASPxRichEdit1.ExportToPdf(pdfStream); RichEditDocumentServer docServer = new RichEditDocumentServer(); docServer.LoadDocument(rtfStream, DocumentFormat.Rtf); using (SqlConnection con = new SqlConnection(conStr)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.Text; cmd.Connection = con; cmd.CommandText = @"update Invoices set InvoiceRtf = @InvoiceRtf, InvoicePdf = @InvoicePdf where OrderID = @OrderID"; cmd.Parameters.AddWithValue("@OrderID", HiddenInvoiceId.Value); cmd.Parameters.AddWithValue("@InvoiceRtf", SqlDbType.VarBinary).Value = rtfStream.ToArray(); cmd.Parameters.AddWithValue("@InvoicePdf", SqlDbType.VarBinary).Value = pdfStream.ToArray(); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } }
static void BeforeImport(RichEditDocumentServer server) { #region #HandleBeforeImportEvent server.LoadDocument("Documents\\TerribleRevengeKOI8R.txt"); server.BeforeImport += BeforeImportHelper.BeforeImport; #endregion #HandleBeforeImportEvent }
private static RichEditDocumentServer GenerateRssFeed() { RichEditDocumentServer rssProcessor = new RichEditDocumentServer(); Document document = rssProcessor.Document; AbstractNumberingList abstractNumberingList = document.AbstractNumberingLists.BulletedListTemplate.CreateNew(); document.NumberingLists.CreateNew(abstractNumberingList.Index); SyndicationFeed feed = null; try { using (XmlReader reader = XmlReader.Create("https://community.devexpress.com/blogs/MainFeed.aspx")) { feed = SyndicationFeed.Load(reader); } } catch { return(null); } document.BeginUpdate(); foreach (SyndicationItem item in feed.Items) { AddSyndicationItem(document, item); } document.EndUpdate(); return(rssProcessor); }
public void DocumentStyle_ListView_Contains_all_styles_from_model_ImportStylesClass_datasource() { using var application = DocumentStyleManagerModule().Application; ModelSetup(application); using (var objectSpace = application.CreateObjectSpace()){ var dataObject = objectSpace.CreateObject <DataObject>(); Document.NewDocumentStyle(1, DocumentStyleType.Paragraph); dataObject.Content = Document.ToByteArray(DocumentFormat.OpenXml); dataObject = objectSpace.CreateObject <DataObject>(); RichEditDocumentServer.CreateNewDocument(); RichEditDocumentServer.Document.NewDocumentStyle(2, DocumentStyleType.Paragraph); RichEditDocumentServer.Document.NewDocumentStyle(1, DocumentStyleType.Character); dataObject.Content = RichEditDocumentServer.Document.ToByteArray(DocumentFormat.OpenXml); RichEditDocumentServer.CreateNewDocument(); dataObject = objectSpace.CreateObject <DataObject>(); RichEditDocumentServer.Document.NewDocumentStyle(2, DocumentStyleType.Character); dataObject.Content = RichEditDocumentServer.Document.ToByteArray(DocumentFormat.OpenXml); objectSpace.CommitChanges(); } var view = (ListView)application.NewView(application.FindListViewId(typeof(DocumentStyle))); var listViewFrame = application.WhenViewOnFrame(typeof(DocumentStyle)).Test(); application.CreateViewWindow().SetView(view); var documentStyles = listViewFrame.Items.First().View.AsListView().CollectionSource.Objects <DocumentStyle>().ToArray(); documentStyles.Length.ShouldBe(8); documentStyles.Count(style => style.DocumentStyleType == DocumentStyleType.Paragraph).ShouldBe(3); documentStyles.Count(style => style.DocumentStyleType == DocumentStyleType.Character).ShouldBe(5); }
private void ApplyRTFModification(RichEditDocumentServer server) { // Apply default formatting server.Document.DefaultCharacterProperties.FontName = "Arial"; server.Document.DefaultCharacterProperties.FontSize = 9; server.Document.DefaultCharacterProperties.ForeColor = Color.FromArgb(120, 120, 120); server.Document.DefaultParagraphProperties.Alignment = ParagraphAlignment.Center; // Remove whitespaces from the end of RTF content DocumentRange[] dots = server.Document.FindAll(".", SearchOptions.None); DocumentPosition lastDot = dots[dots.Length - 1].End; server.Document.Delete(server.Document.CreateRange(lastDot, server.Document.Range.End.ToInt() - lastDot.ToInt())); // Append formatted word DocumentRange range = server.Document.InsertText(server.Document.Range.End, " [Approved]"); CharacterProperties cp = server.Document.BeginUpdateCharacters(range); cp.FontName = "Courier New"; cp.FontSize = 10; cp.ForeColor = Color.Red; cp.Underline = UnderlineType.Single; cp.UnderlineColor = Color.Red; server.Document.EndUpdateCharacters(cp); }
private void button1_Click(object sender, RoutedEventArgs e) { OpenFileDialog ofdlg = new OpenFileDialog(); ofdlg.Multiselect = false; ofdlg.Filter = "Word 97-2003 Files (*.doc)|*.doc"; if (ofdlg.ShowDialog() == true) { image1.Source = null; textBlock1.Text = string.Empty; #region #richserverload richServer = new RichEditDocumentServer(); richServer.CreateNewDocument(); try { richServer.LoadDocument(ofdlg.File.OpenRead(), DocumentFormat.Doc); imgs = richServer.Document.GetImages(richServer.Document.Range); if (imgs.Count > 0) { ShowCurrentImage(); } textBlock1.Text = richServer.Document.Text; } catch (Exception ex) { textBlock1.Text = "Exception occurs:\n" + ex.Message; } #endregion #richserverload button2.IsEnabled = true; this.SimpleAnimation.Completed += new EventHandler(SimpleAnimaton_Completed); this.SimpleAnimation.Begin(); } }
public static Document MergeDouments(List <string> filenames) { RichEditDocumentServer targetServer = new RichEditDocumentServer(); RichEditDocumentServer sourceServer = new RichEditDocumentServer(); Document targetDoc = targetServer.Document; Document sourceDoc = sourceServer.Document; for (int i = 0; i < filenames.Count; i++) { sourceServer.LoadDocument(filenames[i]); targetDoc.Sections[targetDoc.Sections.Count - 1].UnlinkHeaderFromPrevious(); targetDoc.Sections[targetDoc.Sections.Count - 1].UnlinkFooterFromPrevious(); SectionsMerger.Append(sourceDoc, targetDoc); if (i == filenames.Count - 1) { return(targetDoc); } targetDoc.AppendSection(); } return(targetDoc); }
private void button1_Click(object sender, EventArgs e) { captureScreen(); using (RichEditDocumentServer server = new RichEditDocumentServer()) { DevExpress.XtraRichEdit.API.Native.DocumentImage docImage = server.Document.Images.Append(DevExpress.XtraRichEdit.API.Native.DocumentImageSource.FromFile(@"C:\Temp\test.png")); server.Document.Sections[0].Page.Width = docImage.Size.Width + server.Document.Sections[0].Margins.Right + server.Document.Sections[0].Margins.Left; server.Document.Sections[0].Page.Height = docImage.Size.Height + server.Document.Sections[0].Margins.Top + server.Document.Sections[0].Margins.Bottom; // Displays a SaveFileDialog so the user can save the PDF SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "PDF File|*.pdf"; saveFileDialog1.Title = "Save PDF"; saveFileDialog1.ShowDialog(); // If the file name is not an empty string open it for saving. if (saveFileDialog1.FileName != "") { // Saves the Image via a FileStream created by the OpenFile method. System.IO.FileStream fs = (System.IO.FileStream)saveFileDialog1.OpenFile(); server.ExportToPdf(fs); MessageBox.Show("File Saved Successfully !!!"); } } }
private static void SaveDocument(string dir, RichEditDocumentServer documentServer) { var fileName = Path.Combine(dir, $"{Guid.NewGuid()}.docx"); documentServer.SaveDocument(fileName, DocumentFormat.OpenXml); Process.Start(fileName); }
static void CreateBulletedList(RichEditDocumentServer wordProcessor) { #region #CreateBulletedList Document document = wordProcessor.Document; document.LoadDocument("Documents//List.docx"); document.BeginUpdate(); // Create a new list pattern object AbstractNumberingList list = document.AbstractNumberingLists.Add(); //Specify the list's type list.NumberingType = NumberingType.Bullet; ListLevel level = list.Levels[0]; level.ParagraphProperties.LeftIndent = 100; //Specify the bullets' format //Without this step, the list is considered as numbered level.DisplayFormatString = "\u00B7"; level.CharacterProperties.FontName = "Symbol"; //Create a new list based on the specific pattern NumberingList bulletedList = document.NumberingLists.Add(0); // Add paragraphs to the list ParagraphCollection paragraphs = document.Paragraphs; paragraphs.AddParagraphsToList(document.Range, bulletedList, 0); document.EndUpdate(); #endregion #CreateBulletedList }
static void Main(string[] args) { var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var templateFile = Path.Combine(dir, "template.dotx"); var dataFile = Path.Combine(dir, "template.json"); using (var documentServer = new RichEditDocumentServer()) { if (File.Exists(templateFile) && documentServer.LoadFileInDetectionMode(templateFile)) { } else { throw new Exception("Could not load file"); } documentServer.BeginUpdate(); try { var dataText = File.ReadAllText(dataFile); var template = JsonConvert.DeserializeObject <Template>(dataText); InsertItems(documentServer.Document, template); } finally { documentServer.EndUpdate(); } SaveDocument(dir, documentServer); } }
static void WrapTextAroundTable(RichEditDocumentServer wordProcessor) { #region #WrapTextAroundTable Document document = wordProcessor.Document; document.LoadDocument("Documents//Grimm.docx"); Table table = document.Tables.Create(document.Paragraphs[4].Range.Start, 3, 3, AutoFitBehaviorType.AutoFitToContents); table.BeginUpdate(); table.TextWrappingType = TableTextWrappingType.Around; //Specify vertical alignment: table.RelativeVerticalPosition = TableRelativeVerticalPosition.Paragraph; table.VerticalAlignment = TableVerticalAlignment.None; table.OffsetYRelative = DevExpress.Office.Utils.Units.InchesToDocumentsF(2f); //Specify horizontal alignment: table.RelativeHorizontalPosition = TableRelativeHorizontalPosition.Margin; table.HorizontalAlignment = TableHorizontalAlignment.Center; //Set distance between the text and the table: table.MarginBottom = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.3f); table.MarginLeft = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.3f); table.MarginTop = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.3f); table.MarginRight = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.3f); table.EndUpdate(); #endregion #WrapTextAroundTable }
static void UseConditionalStyle(RichEditDocumentServer wordProcessor) { #region #UseConditionalStyle Document document = wordProcessor.Document; document.LoadDocument("Documents\\TableStyles.docx", DocumentFormat.OpenXml); document.BeginUpdate(); // Create a new style that is based on the 'Grid Table 5 Dark Accent 1' style defined in the loaded document. TableStyle myNewStyle = document.TableStyles.CreateNew(); myNewStyle.Parent = document.TableStyles["Grid Table 5 Dark Accent 1"]; // Create conditional styles (styles for table elements) TableConditionalStyle myNewStyleForFirstRow = myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstRow); myNewStyleForFirstRow.CellBackgroundColor = Color.PaleVioletRed; TableConditionalStyle myNewStyleForFirstColumn = myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.FirstColumn); myNewStyleForFirstColumn.CellBackgroundColor = Color.PaleVioletRed; TableConditionalStyle myNewStyleForOddColumns = myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.OddColumnBanding); myNewStyleForOddColumns.CellBackgroundColor = System.Windows.Forms.ControlPaint.Light(Color.PaleVioletRed); TableConditionalStyle myNewStyleForEvenColumns = myNewStyle.ConditionalStyleProperties.CreateConditionalStyle(ConditionalTableStyleFormattingTypes.EvenColumnBanding); myNewStyleForEvenColumns.CellBackgroundColor = System.Windows.Forms.ControlPaint.LightLight(Color.PaleVioletRed); document.TableStyles.Add(myNewStyle); // Create a new table and apply a new style. Table table = document.Tables.Create(document.Range.End, 4, 4, AutoFitBehaviorType.AutoFitToWindow); table.Style = myNewStyle; // Specify which conditonal styles are in effect. table.TableLook = TableLookTypes.ApplyFirstRow | TableLookTypes.ApplyFirstColumn; document.EndUpdate(); #endregion #UseConditionalStyle }
static void MergeDocuments(RichEditDocumentServer wordProcessor) { #region #MergeDocuments wordProcessor.LoadDocument("Documents//Grimm.docx", DocumentFormat.OpenXml); wordProcessor.Document.AppendDocumentContent("Documents//MovieRentals.docx", DocumentFormat.OpenXml); #endregion #MergeDocuments }
static void CreateNewLinkedStyle(RichEditDocumentServer wordProcessor) { #region #CreateNewLinkedStyle Document document = wordProcessor.Document; document.BeginUpdate(); document.AppendText("Line One\nLine Two\nLine Three"); document.EndUpdate(); ParagraphStyle lstyle = document.ParagraphStyles["MyLinkedStyle"]; if (lstyle == null) { document.BeginUpdate(); lstyle = document.ParagraphStyles.CreateNew(); lstyle.Name = "MyLinkedStyle"; lstyle.LineSpacingType = ParagraphLineSpacing.Double; lstyle.Alignment = ParagraphAlignment.Center; document.ParagraphStyles.Add(lstyle); CharacterStyle lcstyle = document.CharacterStyles.CreateNew(); lcstyle.Name = "MyLinkedCStyle"; document.CharacterStyles.Add(lcstyle); lcstyle.LinkedStyle = lstyle; lcstyle.ForeColor = System.Drawing.Color.DarkGreen; lcstyle.Strikeout = StrikeoutType.Single; lcstyle.FontSize = 24; document.EndUpdate(); document.SaveDocument("LinkedStyleSample.docx", DevExpress.XtraRichEdit.DocumentFormat.OpenXml); System.Diagnostics.Process.Start("explorer.exe", "/select," + "LinkedStyleSample.docx"); } #endregion #CreateNewLinkedStyle }
static void PrintDocument(RichEditDocumentServer wordProcessor) { #region #PrintDocument wordProcessor.Document.AppendDocumentContent("Documents\\Grimm.docx", DocumentFormat.OpenXml); wordProcessor.Print(); #endregion #PrintDocument }
public override void Setup() { base.Setup(); RichEditDocumentServer = new RichEditDocumentServer(); RichEditDocumentServer.CreateNewDocument(); Document = RichEditDocumentServer.Document; }
static void EditEndnote(RichEditDocumentServer wordProcessor) { #region #EditEndnote wordProcessor.LoadDocument("Documents//Grimm.docx"); Document document = wordProcessor.Document; //Access the first endnote's content: SubDocument endnote = document.Endnotes[0].BeginUpdate(); //Exclude the reference mark and the space after it from the range to be edited: DocumentRange noteTextRange = endnote.CreateRange(endnote.Range.Start.ToInt() + 2, endnote.Range.Length - 2); //Access the range's character properties: CharacterProperties characterProperties = endnote.BeginUpdateCharacters(noteTextRange); characterProperties.ForeColor = System.Drawing.Color.Red; characterProperties.Italic = true; //Finalize the character options update: endnote.EndUpdateCharacters(characterProperties); //Finalize the endnote update: document.Endnotes[0].EndUpdate(endnote); #endregion #EditEndnote }
private void button1_Click(object sender, RoutedEventArgs e) { #region #xpfprinter RichEditDocumentServer srv = new RichEditDocumentServer(); srv.LoadDocument("test.docx"); FixedDocument document = RichEditDocumentXpfPrinter.CreateFixedDocument(srv); PrintDialog pDialog = new PrintDialog(); PrintQueueCollection queues = new PrintServer().GetPrintQueues(new[] { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections }); System.Collections.IEnumerator localPrinterEnumerator = queues.GetEnumerator(); PrintQueue printQueue = null; do { if (!localPrinterEnumerator.MoveNext()) { break; } printQueue = (PrintQueue)localPrinterEnumerator.Current; }while (!printQueue.FullName.Contains("Canon")); if (printQueue != null) { pDialog.PrintQueue = printQueue; pDialog.PrintDocument(document.DocumentPaginator, string.Empty); } #endregion #xpfprinter }
private void GenerarPDF_Temporal(tblDocumentoContenido contenido, string TipoDocumento, int _orden) { RichEditDocumentServer _reServer = new RichEditDocumentServer(); MemoryStream _ms = new MemoryStream(); string _tempFileName = string.Format("tmp{0}_{1}_{2}_{3}_{4}.pdf", TipoDocumento, contenido.IdEmpresa.ToString("000"), _orden.ToString("00"), contenido.IdDocumento.ToString("000"), contenido.IdSubModulo.ToString("00000000")); string _tempFile = string.Format("{0}/{1}", _tempFilePath, _tempFileName); if (File.Exists(_tempFile)) { File.Delete(_tempFile); } FileStream _fileStream = new FileStream(_tempFile, FileMode.Create); MemoryStream _msData = new MemoryStream(contenido.ContenidoBin.ToArray()); _reServer.Document.LoadDocument(_msData, DevExpress.XtraRichEdit.DocumentFormat.OpenXml); _reServer.ExportToPdf(_ms); _reServer.EndUpdate(); _ms.WriteTo(_fileStream); _ms.Close(); _msData.Close(); _fileStream.Close(); }
public static bool ConvertImageToPdf(Image image, string naziv, RevizijaAPI.Models.Database.dms_file folderOstalo, int id_operater) { using (RichEditDocumentServer server = new RichEditDocumentServer()) { try { //Insert an image DocumentImage docImage = server.Document.Images.Append(DocumentImageSource.FromImage(image)); //Adjust the page width and height to the image's size server.Document.Sections[0].Page.Width = docImage.Size.Width + server.Document.Sections[0].Margins.Right + server.Document.Sections[0].Margins.Left; server.Document.Sections[0].Page.Height = docImage.Size.Height + server.Document.Sections[0].Margins.Top + server.Document.Sections[0].Margins.Bottom; var result = Upload2DMS(folderOstalo, naziv, image, id_operater); if (result.result) { using (FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath($"~\\Uploads\\{result.guid}"), FileMode.OpenOrCreate)) { server.ExportToPdf(fs); } return(true); } else { return(false); } } catch (Exception ex) { return(false); } } }
protected void Page_Load(object sender, EventArgs e) { if (!IsCallback && Request["Template"] != null && Request["ID"] != null) { var TemplateDoc = Request["Template"].ToString(); var ID = Request["ID"].ToString(); RichEditDocumentServer documentServer = new RichEditDocumentServer(); documentServer.LoadDocument(Path.Combine(DirectoryManagmentUtils.CurrentDataDirectory, TemplateDoc)); IEnumerable <CompanyVM> items = GetData(ID); string FileName = "RegisterForm_"; FileName += items.FirstOrDefault()?.Id; FileName += @".docx"; documentServer.Options.MailMerge.DataSource = items; using (MemoryStream stream = new MemoryStream()) { documentServer.MailMerge(stream, DocumentFormat.OpenXml); stream.Position = 0; DocumentManager.CloseDocument(documentId); SaveStreamToFile(stream, Path.Combine(DirectoryManagmentUtils.CurrentDataDirectory, FileName)); stream.Position = 0; SendFiletoClientBrowser(Path.Combine(DirectoryManagmentUtils.CurrentDataDirectory, FileName)); DemoRichEdit.Open(documentId, DocumentFormat.OpenXml, () => { return(stream); }); } } }
private void barButtonItem1_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { int count = ((List <Employee>)richEditControl1.Options.MailMerge.DataSource).Count; SaveFileDialog saveFileDialog1 = new SaveFileDialog(); saveFileDialog1.Filter = "PDF files (*.pdf)|*.pdf|All files (*.*)|*.*"; saveFileDialog1.FilterIndex = 1; saveFileDialog1.RestoreDirectory = true; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (RichEditDocumentServer docServer = new RichEditDocumentServer()) { MailMergeOptions options = richEditControl1.CreateMailMergeOptions(); for (int i = 0; i < count; i++) { string filename = string.Format("{0}{1}.pdf", saveFileDialog1.FileName, (i + 1).ToString()); options.FirstRecordIndex = options.LastRecordIndex = i; using (FileStream fs = new FileStream(filename, FileMode.Create, System.IO.FileAccess.Write)) { richEditControl1.MailMerge(options, docServer.Document); docServer.ExportToPdf(fs); } } } } }
private static void PrintViaLink(RichEditDocumentServer srv) { if (!srv.IsPrintingAvailable) { return; } using (PrintingSystemBase ps = new PrintingSystemBase()) using (PrintableComponentLinkBase link = new PrintableComponentLinkBase(ps)) { link.Component = srv; // Disable warnings. ps.ShowMarginsWarning = false; ps.ShowPrintStatusDialog = false; // Find a printer containing 'Canon' in its name. string printerName = String.Empty; for (int i = 0; i < PrinterSettings.InstalledPrinters.Count; i++) { string pName = PrinterSettings.InstalledPrinters[i]; if (pName.Contains("PDF")) { printerName = pName; break; } } //Run document creaion link.CreateDocument(); // Print to the specified printer. PrintToolBase tool = new PrintToolBase(ps); tool.Print(printerName); } }
void OpenDocumentAndShowReport() { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { if (openFileDialog1.OpenFile() != null) { using (RichEditDocumentServer reds = new RichEditDocumentServer()) { reds.LoadDocument(openFileDialog1.FileName); using (XtraReport1 report = new XtraReport1()) { report.RichText.Rtf = reds.RtfText; report.ShowPreviewDialog(); } } } } catch (Exception ex) { MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message); } } }
static void FormatParagraph(RichEditDocumentServer wordProcessor) { #region #FormatParagraph Document document = wordProcessor.Document; document.BeginUpdate(); document.AppendText("Modified Paragraph\nNormal\nNormal"); document.EndUpdate(); DocumentPosition pos = document.Range.Start; DocumentRange range = document.CreateRange(pos, 0); ParagraphProperties pp = document.BeginUpdateParagraphs(range); // Center paragraph pp.Alignment = ParagraphAlignment.Center; // Set triple spacing pp.LineSpacingType = ParagraphLineSpacing.Multiple; pp.LineSpacingMultiplier = 3; // Set left indent at 0.5". // Default unit is 1/300 of an inch (a document unit). pp.LeftIndent = DevExpress.Office.Utils.Units.InchesToDocumentsF(0.5f); // Set tab stop at 1.5" TabInfoCollection tbiColl = pp.BeginUpdateTabs(true); TabInfo tbi = new DevExpress.XtraRichEdit.API.Native.TabInfo(); tbi.Alignment = TabAlignmentType.Center; tbi.Position = DevExpress.Office.Utils.Units.InchesToDocumentsF(1.5f); tbiColl.Add(tbi); pp.EndUpdateTabs(tbiColl); document.EndUpdateParagraphs(pp); #endregion #FormatParagraph }
// Fourth stage. For each Order ID create a detailed document that will be inserted in place of the DOCVARIABLE field. // This is the final stage and the Product.Orders template does not contain DOCVARIABLE fields. So, further processing is not required. void richServerDetail_CalculateDocumentVariable(object sender, CalculateDocumentVariableEventArgs e) { int currentProductID = GetID(e.Arguments[0].Value); if (currentProductID == -1) { return; } if (productID != currentProductID) { // Get data source that contains orders for the specified product. // The data source is obtained from the data already filtered by supplier. dataDetailedForOrders = GetOrderDataFilteredbyProductAndSupplier(currentProductID); productID = currentProductID; } if (e.VariableName == "OrderDetails") { RichEditDocumentServer richServerDetailDetail = new RichEditDocumentServer(); MailMergeOptions options = ordersRichEdit.CreateMailMergeOptions(); options.DataSource = dataDetailedForOrders; options.MergeMode = MergeMode.JoinTables; ordersRichEdit.MailMerge(options, richServerDetailDetail); e.Value = richServerDetailDetail; e.Handled = true; } }
private static void ConvertFilesODTtoDOCX(DirectoryInfo directory) { RichEditDocumentServer server = new RichEditDocumentServer(); String newName = string.Empty; server.Options.Export.Html.EmbedImages = true; foreach (FileInfo file in directory.GetFiles()) { if (file.Extension.Equals(".odt") || file.Extension.Equals("odt")) { server.LoadDocument(@file.FullName, DocumentFormat.OpenDocument); //Console.WriteLine(file.FullName); newName = file.Name.Replace(file.Extension, ""); //Console.WriteLine(newName); server.SaveDocument(directory.FullName + Path.DirectorySeparatorChar + newName, DocumentFormat.OpenXml); try { file.Delete(); } catch (Exception) { //Do nothing } } } foreach (DirectoryInfo dir in directory.GetDirectories()) { if (!dir.Name.Equals("TEMPORALES") && !dir.Name.Equals("ERROR_LOGS")) { ConvertFilesODTtoDOCX(dir); } } }
public ActionResult RichEditCustomPartial(int?position) { ViewData["RTF"] = rtf; if (position != null) { MemoryStream memoryStream = new MemoryStream(); RichEditExtension.SaveCopy("RichEdit", memoryStream, DocumentFormat.Rtf); memoryStream.Position = 0; var server = new RichEditDocumentServer(); server.LoadDocument(memoryStream, DocumentFormat.Rtf); var pos = server.Document.CreatePosition(position.Value); server.Document.InsertRtfText(pos, rtf); memoryStream = new MemoryStream(); server.SaveDocument(memoryStream, DocumentFormat.Rtf); var model = new RichEditData { DocumentId = Guid.NewGuid().ToString(), Document = memoryStream.ToArray(), DocumentFormat = DocumentFormat.Rtf }; return(PartialView("_RichEditPartial", model)); } return(PartialView("_RichEditPartial")); }
static void Main(string[] args) { using (RichEditDocumentServer wordProcessor = new RichEditDocumentServer()) { //Register the created service implementation wordProcessor.LoadDocument("Multimodal.docx"); //Load embedded dictionaries var openOfficePatternStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("word_processing_hyphenation.hyphen.dic"); var customDictionaryStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("word_processing_hyphenation.hyphen_exc.dic"); //Create dictionary objects OpenOfficeHyphenationDictionary hyphenationDictionary = new OpenOfficeHyphenationDictionary(openOfficePatternStream, new System.Globalization.CultureInfo("EN-US")); CustomHyphenationDictionary exceptionsDictionary = new CustomHyphenationDictionary(customDictionaryStream, new System.Globalization.CultureInfo("EN-US")); //Add them to the word processor's collection wordProcessor.HyphenationDictionaries.Add(hyphenationDictionary); wordProcessor.HyphenationDictionaries.Add(exceptionsDictionary); //Specify hyphenation settings wordProcessor.Document.Hyphenation = true; wordProcessor.Document.HyphenateCaps = true; //Export the result to the PDF format wordProcessor.ExportToPdf("Result.pdf"); } //Open the result Process.Start("Result.pdf"); }
void QuoteReplyMessage(RichEditDocumentServer server, string to, DateTime originalMessageDate) { QuoteMessage(server); Document document = server.Document; string replyHeader = String.Format( Properties.Resources.ReplyText, to, originalMessageDate ); document.InsertText(document.Range.Start, replyHeader); }
void QuoteMessage(RichEditDocumentServer server) { Document document = server.Document; ParagraphCollection paragraphs = document.Paragraphs; foreach (Paragraph paragraph in paragraphs) { DocumentRange range = paragraph.Range; if (document.GetTableCell(range.Start) == null && !paragraph.IsInList) { document.InsertText(range.Start, ">> "); } } }
string CreateReplyMessageText(string text, string to, DateTime originalMessageDate) { using (RichEditDocumentServer server = new RichEditDocumentServer()) { server.HtmlText = text; QuoteReplyMessage(server, to, originalMessageDate); return server.HtmlText; } }
void QuoteForwardMessage(RichEditDocumentServer server, string to) { Document document = server.Document; string replyHeader = Properties.Resources.ForwardTextStart; document.InsertText(document.Range.Start, replyHeader); document.AppendText(Properties.Resources.ForwardTextStart); }
string CreateForwardMessageText(string text, string to) { using (RichEditDocumentServer server = new RichEditDocumentServer()) { server.HtmlText = text; QuoteForwardMessage(server, to); return server.HtmlText; } }