You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi,
We recently updated from 2.0.1 to 2.0.2 and after the update the import of the images from html file to docx is not longer working when the document is created from a template. The document is created from a blank template.
var templatePath = "Empty.dotx";
var html = File.ReadAllText(path + "\\ImagePage.html");
var doc = WordprocessingDocument.CreateFromTemplate(templatePath);
var mainPart = doc.MainDocumentPart;
HtmlConverter converter = new HtmlConverter(mainPart)
{
ImageProcessing = ImageProcessing.ManualProvisioning,
BaseImageUrl = new Uri(path)
};
converter.ProvisionImage += OnProvisionImage;
converter.ParseHtml(html);
doc.SaveAs(@"D:\temp\doc.docx");
doc.Close();
Thanks
The text was updated successfully, but these errors were encountered:
Could you share with me the content of OnProvisionImage?
I don't know what is behind doc.SaveAs but ensure you have called mainPart.Document.Save() to persist the parsed chunks into the document.
This is the the code:
static void OnProvisionImage(object sender, ProvisionImageEventArgs e)
{
var documentPath = (sender as HtmlConverter).BaseImageUrl.OriginalString;
string fileName = e.ImageUrl.OriginalString;
e.Provision(File.ReadAllBytes(fileName));
}
I need to use SaveAs because it comes from a template and I it does not have an option on create for filename.
Html is like this:
Hi,
We recently updated from 2.0.1 to 2.0.2 and after the update the import of the images from html file to docx is not longer working when the document is created from a template. The document is created from a blank template.
Thanks
The text was updated successfully, but these errors were encountered: