Skip to content

Conversation

@onizet
Copy link
Owner

@onizet onizet commented Oct 20, 2025

onizet and others added 13 commits September 4, 2025 21:17
1. Specify an ID in AddImagePart to avoid duplicate key issues when handling multiple images. (#215)
2. Add thread-safe image cache handling
…dled during conversion. (#216)

The idea of this commit is to provide a working example of being able to dictate how HtmlToOpenXml should handle images marked as HTTP/HTTPS. I've also provided handling for data uris so that only data URI images can be embedded.

Example implementation - taken from a modified form of examples\Demo\Program.cs

    string inputFile = "C:\\ConvertedHtml.html";
    string htmlContent = await File.ReadAllTextAsync(inputFile);

    string outputPath = "C:\\ConvertedHtml.docx";
    using WordprocessingDocument wordDoc = WordprocessingDocument.Create(outputPath, WordprocessingDocumentType.Document);
    MainDocumentPart mainPart = wordDoc.AddMainDocumentPart();
    mainPart.Document = new Document(new DocumentFormat.OpenXml.Wordprocessing.Body());

    HtmlConverter htmlConverter = new(mainPart, new DefaultWebRequest())
    {
        ImageProcessing = ImageProcessingMode.LinkExternal
    };

    await htmlConverter.ParseBody(htmlContent);

    AssertThatOpenXmlDocumentIsValid(wordDoc);

    mainPart.Document.Save();
… MemoryStream, resulting in premature disposal
@sonarqubecloud
Copy link

@onizet onizet merged commit 86308db into master Oct 20, 2025
3 checks passed
@onizet onizet changed the title Release 3.8 Release 3.2.8 Oct 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants