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.

Sat Jan 20, 2024 3:55 pm

Hi,
We import HTML with code (SpireDoc 11.7.0 for Java) with code:
Code: Select all
        Document doc = new Document();
        doc.addSection().addParagraph().appendHTML("<p style=\"font-size:25px\">Test</p>");
        doc.saveToFile("test.doc", FileFormat.Docx_2019);


But in document we see different font size. Is there option to get same font size on HTML import?
html_font.png


Thanks,
Andrei Chorin

andrei.chorin
 
Posts: 68
Joined: Sun Jan 08, 2023 2:36 pm

Mon Jan 22, 2024 2:55 am

Hello,

Thank you for your inquiry.
Please note that the unit of font size in Microsoft Word is "points" (pt), not pixels (px). Therefore, if you set a font size of 25px in HTML, it will be displayed as 19pt in Microsoft Word. If you wish to have consistent font sizes between your HTML and Microsoft Word documents, please modify the unit of the font size accordingly.
For example, you can modify the font size unit in your code as follows:
Code: Select all
doc.addSection().addParagraph().appendHTML("<p style=\"font-size:25pt\">Test</p>");

By changing the unit to "pt," the font size set in the HTML will be correctly reflected in Microsoft Word.
Additionally, if you need to convert font sizes from pixels (px) to points (pt), you can use the following code snippet:
Code: Select all
private static float ConvertPxToPt(float px){
    float result = px *3 /4;
    return  result;
}

If you have any further questions or need additional assistance, please feel free to reach out to us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Jan 22, 2024 7:45 am

Hi, thanks for quick answer.
This 0.75 ratio is on 96DPI, do we any option to change DPI in html import?

Thanks,
Andrei Chorin.

andrei.chorin
 
Posts: 68
Joined: Sun Jan 08, 2023 2:36 pm

Mon Jan 22, 2024 8:22 am

Hello,

Thank you for your feedback.
Yes, the conversion ratio of 0.75 is based on a DPI value of 96. However, I regret to inform you that our Spire.Doc library does not currently offer an interface or overload method to modify the DPI when importing HTML. I apologize for any inconvenience this may cause.
If you have any further questions or require additional assistance, please feel free to reach out to us.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Return to Spire.Doc

cron