Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Wed Feb 08, 2023 8:45 am

Hello,

I'm trying to resize the image from HTML to word document using spire.doc. Please find below the HTML, .net code snippet
HTML:
<p>
<img class="image_resized" style="width:17.04%;" src="317-3172063_transparent-background-png-online-online-business-logo-png.png"> &nbsp;<span style="color:#000000;font-family:'Times New Roman', Times, serif;font-size:18px;"><strong> Test Report</strong></span>
</p>

.NET:
document.HtmlExportOptions.ImageEmbedded = true;
document.HtmlExportOptions.CssStyleSheetType = CssStyleSheetType.Internal;

But the image is not correctly resized in word document, in pdf it shows correctly.

Did I miss anything here? Please suggest!

Thanks in advance!

ranjanirj
 
Posts: 3
Joined: Mon Feb 06, 2023 2:39 pm

Wed Feb 08, 2023 10:25 am

Hi,

Thanks for your inquiry.
I added an image and did the test with your html string by using the latest Spire.Doc(11.1.4), but I did not reproduce your issue. I have attached my code and html file for your reference. You can test them on your side. If only your html file has the issue, please provide us with the following messages to help us for further investigation. You can send them to us via email (support@e-iceblue.com) or attach them here. Thanks for your assistance.
1) your full code and the picture in your html file.
2) the version of Spire.Doc in your project.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Thu Feb 09, 2023 8:40 am

Hi,

Thanks for immediate response!

We are converting stream into document and not directly from HTML content as you mentioned in sample code.
document.LoadFromStream(stream, FileFormat.Html, XHTMLValidationType.None);

My query here is, even for loading document from stream,
1. Are not required the the below lines?

/*doc.HtmlExportOptions.ImageEmbedded = true;
doc.HtmlExportOptions.CssStyleSheetType = CssStyleSheetType.Internal;*/

Since you have commented these two lines in your sample code.

2.If not required then when we should use these lines especially the imageEmbedded = true ?

3. We are using spire.Doc version 10.12.4.0. If I include imageEmbedded = truein my code then the image in document is not displaying properly. If I commented the piece of code then it will display as expected.


Thanks!

ranjanirj
 
Posts: 3
Joined: Mon Feb 06, 2023 2:39 pm

Thu Feb 09, 2023 10:11 am

Hi,

Thanks for your feedback.
For your question 1 and 2. The 2 lines of code are used for exporting Word document into Html, See the attached demo for your reference.
Code: Select all
 
           //Open a Word document.
            Document document = new Document();
            document.LoadFromFile("test.docx");
            //Set whether the css styles are embeded or not.
            document.HtmlExportOptions.CssStyleSheetFileName = "sample.css";
            document.HtmlExportOptions.CssStyleSheetType = CssStyleSheetType.External;
           
            //Set whether the images are embeded or not.
            document.HtmlExportOptions.ImageEmbedded = false;
            document.HtmlExportOptions.ImagesPath = "Images";
           
            //Set the option whether to export form fields as plain text or not.
            document.HtmlExportOptions.IsTextInputFormFieldAsText = true;
           
            //Save the document to a html file.
            document.SaveToFile("Sample.html",FileFormat.Html);


For the question 3, the code is designed for exporting Word document into Html, if you use it for converting Html to Word, some unexpected situations may occur.
If you have any other questions related to our products, just feel free to contact us.

Sincerely,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc