We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

How do I get the images out of a sfRichTextAdv control

Thread ID:

Created:

Updated:

Platform:

Replies:

131808 Jul 28,2017 12:03 AM Jul 28,2017 08:54 AM UWP 1
loading
Tags: SfRichTextBoxAdv
Lee Davies
Asked On July 28, 2017 12:03 AM

I have a complex document created in the SfRichTextBoxAvd and I want to pull all the images from the document.

I added the image to the SfRichTextBoxAvd using the following code

 private async void InsertPictureButton_Click(object sender, RoutedEventArgs e)
        {
            var fileOpenPicker = new FileOpenPicker();
            fileOpenPicker.FileTypeFilter.Add(".png");
            fileOpenPicker.FileTypeFilter.Add(".jpg");
            var stgFile = await fileOpenPicker.PickSingleFileAsync();
            if (stgFile != null)
            {
                RichTextBoxAdv.InsertPictureCommand.Execute(stgFile);
            }
        }

I can get the ImageContainerAdv from the SfRichTextBoxAvd using the following code

 foreach (SectionAdv section in RichTextBoxAdv.Document.Sections)
            {
                foreach (ParagraphAdv block in section.Blocks)
                {
                    foreach (var inline in block.Inlines)
                    {
                        if (inline is ImageContainerAdv imageContainer)
                        {

imageContainer gives me the ImageSource and the ImageString (the latter is always empty).

However I cannot get the image content or any of the metadata associated with the image (file name and image mime type) from the imageContainer

My fallback is to convert the contents to html and then pull the base64 image from the img tags, however this feels like a kludge and does not get me the original file name.

Venkatesan Mani [Syncfusion]
Replied On July 28, 2017 08:54 AM

Hi Lee Davies,

Thank you for using Syncfusion products.

Our ImageContainerAdv does not preserve file name or mime type when inserting image using InsertPicture command. However we have provided an option to specify HTML export settings from our Essential Studio version v15.2.0.43. Using the event “ImageNodeVisitedEvent” of HtmlImportExportOptions instance, you will have the image data as stream. You can process the stream and specify the image string to be exported in HTML. Please find the release notes and API reference below.

https://help.syncfusion.com/uwp/release-notes/v15.2.0.43?type=all#sfrichtextboxadv

http://help.syncfusion.com/cr/cref_files/uwp/sfrichtextboxadv/frlrfSyncfusionUIXamlRichTextBoxAdvHtmlImportExportSettingsClassImageNodeVisitedTopic.html

http://help.syncfusion.com/cr/cref_files/uwp/sfrichtextboxadv/frlrfSyncfusionUIXamlRichTextBoxAdvImageNodeVisitedEventArgsClassSourceTopic.html

We have prepared a sample using ImageNodeVisited event to process the stream, save it in local storage and specify the path to be exported in HTML Please find the same from the following link.

Sample link:
Sample.zip

Try running the sample and let us know if this helps you.

Regards,
Venkatesan M. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;