I am looking for some advice on extracting “images” from a word document into files in their own right.
Ideally, I would like to get Shape, Textbox, and Picture elements in a format that lets me save them as an image representation.
This seems to be possible with Picture (using PictureStream) but the other elements don’t have an image representation.
The use of a FilesDirectoryPath in HtmlSaveOptions seems to back this up as shapes and textboxes are ignored from this even when they are just “images” on the page.
Hi Mario,
I won’t get chance to look at this until tomorrow, unfortunately, but this looks promising.
Just a thought…If the .FormatDrawing().Save() method would support saving to a stream that would be perfect. I am uploading these files to cloud storage so having to create “temp” files locally, read them back in and upload them is just a bit annoying.
Update:
I get this error One or more errors occurred. (Could not load file or assembly 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'. The system cannot find the file specified.)
When I execute this line: using var ms = new MemoryStream(); source.FormatDrawing().Save(ms,new ImageSaveOptions(ImageSaveFormat.Png));
Turns out it’s dead easy to make this work…well on my local environment anyway…
I’ve just added the “UseWPF” line into my csproj file… <PropertyGroup> <TargetFramework>netcoreapp3.1</TargetFramework> <UseWPF>true</UseWPF> </PropertyGroup>
Note that the current latest version of GemBox.Document has cross-platform support for saving documents to images. https://www.nuget.org/packages/GemBox.Document/
In other words, there is no longer a need to enable WPF when calling the DrawingElement.FormatDrawing() method.