|
13 | 13 | using WDocument = Syncfusion.DocIO.DLS.WordDocument; |
14 | 14 | using WFormatType = Syncfusion.DocIO.FormatType; |
15 | 15 | using Syncfusion.EJ2.SpellChecker; |
16 | | -using EJ2DocumentEditorServer; |
17 | 16 |
|
18 | 17 | namespace EJ2DocumentEditorServer.Controllers |
19 | 18 | { |
@@ -44,12 +43,47 @@ public string Import(IFormCollection data) |
44 | 43 | file.CopyTo(stream); |
45 | 44 | stream.Position = 0; |
46 | 45 |
|
| 46 | + //Hooks MetafileImageParsed event. |
| 47 | + WordDocument.MetafileImageParsed += OnMetafileImageParsed; |
47 | 48 | WordDocument document = WordDocument.Load(stream, GetFormatType(type.ToLower())); |
| 49 | + //Unhooks MetafileImageParsed event. |
| 50 | + WordDocument.MetafileImageParsed -= OnMetafileImageParsed; |
| 51 | + |
48 | 52 | string json = Newtonsoft.Json.JsonConvert.SerializeObject(document); |
49 | 53 | document.Dispose(); |
50 | 54 | return json; |
51 | 55 | } |
52 | 56 |
|
| 57 | + //Converts Metafile to raster image. |
| 58 | + private static void OnMetafileImageParsed(object sender, MetafileImageParsedEventArgs args) |
| 59 | + { |
| 60 | + //You can write your own method definition for converting metafile to raster image using any third-party image converter. |
| 61 | + args.ImageStream = ConvertMetafileToRasterImage(args.MetafileStream); |
| 62 | + } |
| 63 | + |
| 64 | + private static Stream ConvertMetafileToRasterImage(Stream ImageStream) |
| 65 | + { |
| 66 | + //Here we are loading a default raster image as fallback. |
| 67 | + Stream imgStream = GetManifestResourceStream("ImageNotFound.jpg"); |
| 68 | + return imgStream; |
| 69 | + //To do : Write your own logic for converting metafile to raster image using any third-party image converter(Syncfusion doesn't provide any image converter). |
| 70 | + } |
| 71 | + |
| 72 | + private static Stream GetManifestResourceStream(string fileName) |
| 73 | + { |
| 74 | + System.Reflection.Assembly execAssembly = typeof(WDocument).Assembly; |
| 75 | + string[] resourceNames = execAssembly.GetManifestResourceNames(); |
| 76 | + foreach (string resourceName in resourceNames) |
| 77 | + { |
| 78 | + if (resourceName.EndsWith("." + fileName)) |
| 79 | + { |
| 80 | + fileName = resourceName; |
| 81 | + break; |
| 82 | + } |
| 83 | + } |
| 84 | + return execAssembly.GetManifestResourceStream(fileName); |
| 85 | + } |
| 86 | + |
53 | 87 | [AcceptVerbs("Post")] |
54 | 88 | [HttpPost] |
55 | 89 | [EnableCors("AllowAllOrigins")] |
@@ -118,7 +152,11 @@ public string SystemClipboard([FromBody]CustomParameter param) |
118 | 152 | { |
119 | 153 | try |
120 | 154 | { |
| 155 | + //Hooks MetafileImageParsed event. |
| 156 | + WordDocument.MetafileImageParsed += OnMetafileImageParsed; |
121 | 157 | WordDocument document = WordDocument.LoadString(param.content, GetFormatType(param.type.ToLower())); |
| 158 | + //Unhooks MetafileImageParsed event. |
| 159 | + WordDocument.MetafileImageParsed -= OnMetafileImageParsed; |
122 | 160 | string json = Newtonsoft.Json.JsonConvert.SerializeObject(document); |
123 | 161 | document.Dispose(); |
124 | 162 | return json; |
|
0 commit comments