Image not exported when upload from Document Editor Container Angular

the image cannot be exported if I save it from the Angular application but if we create it from the Microsoft Word application and add an image in it, and export to sfdt then it will be exported accordingly

Angular & Syncfusion version


.NET Core & Syncfusion version 


Here I provide some supporting files

  • dico-v1.png  -> example image upload
  • save_document_editor.docx -> word document create and save from my application (image not exported correcly)
  • save_office_word_office_application.docx -> word document create and save from ms word application (image exported correcly)

.NET Save Source Code
        public void Save(SaveParameter data)
        {
            string name = data.FileName != null ? data.FileName : "Saveddoc.docx";
            string format = RetrieveFileType(name);
            if (string.IsNullOrEmpty(name))
            {
                name = "Document1.docx";
            }
            WDocument document = Syncfusion.EJ2.DocumentEditor.WordDocument.Save(data.Content);
            FileStream fileStream = new FileStream(basePath + name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
            document.Save(fileStream, GetWFormatType(format));
            document.Close();
            fileStream.Close();
        }


.NET Export  Source Code
        public string? LoadDocument(UploadDocument uploadDocument)
        {
            if (basePath == null || uploadDocument.DocumentName == null)
            {
                return null;
            }
            string documentPath = uploadDocument.DocumentName.StartsWith('/')
                ? basePath + uploadDocument.DocumentName
                : basePath + uploadDocument.DocumentName;
            Stream? stream = null;
            if (System.IO.File.Exists(documentPath))
            {
                byte[] bytes = System.IO.File.ReadAllBytes(documentPath);
                stream = new MemoryStream(bytes);
            }
            else
            {
                bool result = Uri.TryCreate(documentPath, UriKind.Absolute, out Uri uriResult)
                    && (uriResult.Scheme == Uri.UriSchemeFile);
                if (result && documentPath != null)
                {
                    stream = GetDocumentFromURL(documentPath).Result;
                    if (stream != null)
                        stream.Position = 0;
                }
            }

            //Hooks MetafileImageParsed event.
            WordDocument.MetafileImageParsed += OnMetafileImageParsed;

            //Converts Stream DOM to SFDT DOM.
            WordDocument document = WordDocument.Load(stream, FormatType.Docx);

            //Unhooks MetafileImageParsed event.
            WordDocument.MetafileImageParsed -= OnMetafileImageParsed;

            //Serializes SFDT DOM to SFDT string.
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(document);
            document.Dispose();
            return json;
        }

        private static void OnMetafileImageParsed(object sender, MetafileImageParsedEventArgs args)
        {
            //You can write your own method definition for converting metafile to raster image using any third-party image converter.
            args.ImageStream = ConvertMetafileToRasterImage(args.MetafileStream);
        }

        private static Stream ConvertMetafileToRasterImage(Stream metafileStream)
        {
            using var memStream = new MemoryStream();
            var basicInfo = new MagickImageInfo(metafileStream);
            var settings = new MagickReadSettings();
            settings.Width = basicInfo.Width;
            settings.Height = basicInfo.Height;
            settings.Format = basicInfo.Format;
            var image = new MagickImage(metafileStream, settings);
            image.Format = basicInfo.Format;
            image.Write(memStream);
            return memStream;
        }

Attachment: save_document_editor_d6c4c2ea.zip

3 Replies

SK Selvaprakash Karuppusamy Syncfusion Team May 29, 2023 07:52 AM UTC

Hi Muhammad,


We can reproduce the reported issue with the provided details. Currently, we are validating and will get back to you by May 31, 2023. 


Regards,

Selvaprakash K




SK Selvaprakash Karuppusamy Syncfusion Team May 31, 2023 10:40 AM UTC

Hi Muhammad, 


We are glad to announce that our patch release (v21.2.8) has been rolled out successfully. In this release, we have added the fix for the issue 'Resolve data loss issue - Image with hidden property'.

Please upgrade to the latest version packages to resolve this issue:

Npm link:

https://www.npmjs.com/package/@syncfusion/ej2-angular-documenteditor

NuGet link:

https://www.nuget.org/packages/Syncfusion.Ej2.Wordeditor.ASPNet.Core/

https://www.nuget.org/packages/Syncfusion.Ej2.Wordeditor.ASPNet.MVC5/

Feedback Link:

https://www.syncfusion.com/feedback/43018/resolve-data-loss-issue-image-with-hidden-property


Please let us know if you need any further assistance. 


Regards,

Selvaprakash K



MD Muhammad Dani Rhamadan replied to Selvaprakash Karuppusamy May 31, 2023 11:59 AM UTC

Hi Selvaprakash..

Thankyou 👍


Loader.
Up arrow icon