Hi,
When converting a DOCX to PDF, we used ImageSavingCallback to record some location information with the image that gets converted.
It worked fine when MetafileFormat is the default Png value but it is no longer triggered when the value is set to Svg.
Code:
var doc = new Document(@".\test.docx");
var htmlSaveOptions = new HtmlSaveOptions
{
ImageSavingCallback = new HtmlImageSavingCallback(), // my callback class is provided below
MetafileFormat = HtmlMetafileFormat.Svg // worked find if I changed to .Png
};
doc.Save(@".\out.html", htmlSaveOptions);
and my callback class is
public class HtmlImageSavingCallback : IImageSavingCallback
{
/// <summary>
/// Called when Aspose.Words saves an image to HTML.
/// </summary>
public void ImageSaving(ImageSavingArgs args)
{
NameToFileNameDictionary[args.CurrentShape.Name] = args.ImageFileName;
var tag = args.CurrentShape.ParentNode as StructuredDocumentTag;
if (tag == null)
{
tag = args.CurrentShape.ParentNode.ParentNode as StructuredDocumentTag;
if (tag == null)
{
tag = args.CurrentShape.ParentNode.ParentNode.ParentNode as StructuredDocumentTag;
if (tag == null)
return;
}
}
string imageId = tag.Tag.GetTag("LinkedId_", MatchingMethod.StartsWith);
if (!string.IsNullOrEmpty(imageId))
imageId = imageId.Substring(9);
else
imageId = tag.Id.ToString();
TagIdToFileNameDictionary[imageId] = args.ImageFileName;
}
public Dictionary<string, string> TagIdToFileNameDictionary { get; } = new Dictionary<string, string>();
public Dictionary<string, string> NameToFileNameDictionary { get; } = new Dictionary<string, string>();
}
The callback retrieves some tags of the content control that contains the EMF image after rendering, and we use the data for some additional processing.
I’ve attached an example docx file for your reference. Can we also trigger the callback when the images are saved as SVG?
test.docx (17.9 KB)
Thanks,