public HttpResponseMessage Import(int id) { DTO_CUS_DOC_File tbl_CUS_DOC_File = BS_CUS_DOC_File.get_CUS_DOC_File(db, PartnerID, id, true); if (tbl_CUS_DOC_File == null || !(tbl_CUS_DOC_File.Extension == "docx" || tbl_CUS_DOC_File.Extension == "doc")) { return(null); } string path = System.Web.HttpContext.Current.Server.MapPath("~") + tbl_CUS_DOC_File.Path; string json = ""; System.IO.FileInfo fileInfo = new FileInfo(path); if (fileInfo.Exists) { Stream stream = File.OpenRead(path); Syncfusion.EJ2.DocumentEditor.WordDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.Load(stream, GetFormatType("." + tbl_CUS_DOC_File.Extension.ToLower())); json = Newtonsoft.Json.JsonConvert.SerializeObject(document); // Releases unmanaged and optionally managed resources. document.Dispose(); stream.Close(); } return(new HttpResponseMessage() { Content = new StringContent(json, System.Text.Encoding.UTF8, "text/plain") }); }
public HttpResponseMessage SystemClipboard([FromBody] CustomParameter param) { if (param.content != null && param.content != "") { try { Syncfusion.EJ2.DocumentEditor.WordDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.LoadString(param.content, GetFormatType(param.type.ToLower())); string json = Newtonsoft.Json.JsonConvert.SerializeObject(document); document.Dispose(); return(new HttpResponseMessage() { Content = new StringContent(json) }); } catch (Exception) { return(new HttpResponseMessage() { Content = new StringContent("") }); } } return(new HttpResponseMessage() { Content = new StringContent("") }); }
public HttpResponseMessage MailMerge([FromBody] ExportData exportData) { Byte[] data = Convert.FromBase64String(exportData.documentData.Split(',')[1]); MemoryStream stream = new MemoryStream(); stream.Write(data, 0, data.Length); stream.Position = 0; try { Syncfusion.DocIO.DLS.WordDocument document = new Syncfusion.DocIO.DLS.WordDocument(stream, Syncfusion.DocIO.FormatType.Docx); document.MailMerge.RemoveEmptyGroup = true; document.MailMerge.RemoveEmptyParagraphs = true; document.MailMerge.ClearFields = true; document.MailMerge.Execute(CustomerDataModel.GetAllRecords()); document.Save(stream, Syncfusion.DocIO.FormatType.Docx); } catch (Exception) { } string sfdtText = ""; EJ2WordDocument worddocument = EJ2WordDocument.Load(stream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx); sfdtText = Newtonsoft.Json.JsonConvert.SerializeObject(worddocument); worddocument.Dispose(); return(new HttpResponseMessage() { Content = new StringContent(sfdtText) }); }
public string ImportWordDocument(Stream stream) { string sfdtText = ""; EJ2WordDocument document = EJ2WordDocument.Load(stream, Syncfusion.EJ2.DocumentEditor.FormatType.Docx); sfdtText = Newtonsoft.Json.JsonConvert.SerializeObject(document); document.Dispose(); return(sfdtText); }
public string SystemClipboard([FromBody] CustomParameter param) { if (param.content != null && param.content != "") { Syncfusion.EJ2.DocumentEditor.WordDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.LoadString(param.content, GetFormatType(param.type.ToLower())); string json = Newtonsoft.Json.JsonConvert.SerializeObject(document); document.Dispose(); return(json); } return(""); }
public HttpResponseMessage Import() { if (HttpContext.Current.Request.Files.Count == 0) { return(null); } HttpPostedFile file = HttpContext.Current.Request.Files[0]; int index = file.FileName.LastIndexOf('.'); string type = index > -1 && index < file.FileName.Length - 1 ? file.FileName.Substring(index) : ".docx"; Stream stream = file.InputStream; stream.Position = 0; EJ2WordDocument document = EJ2WordDocument.Load(stream, GetFormatType(type.ToLower())); string json = Newtonsoft.Json.JsonConvert.SerializeObject(document); document.Dispose(); return(new HttpResponseMessage() { Content = new StringContent(json) }); }