Hi,
When converting this .docx to .html, seems like the font-size is missing around the “Test2” text which has a style _test (Verdana, 12pt) based on _Normal (Arial, 8pt). Modifying _test to 20pt in my second document makes the font-size appear as you can see in the comparison in image.png.
I thought the font-size didn’t appear as it might be the same as the default which appears as a body style in the HTML, but that default is 11pt and not 12pt. I can see that the “test2” span is taking the default font-size coming from table: font-size:medium, which just by luck seems to be 12pt.
Word does create a class p.test which has the font-size in it. Can you please let us know why the font-family doesn’t appear with 12pt with Aspose?
Can you please add it in that case as it appears with other sizes? It is important to us so we can modify the HTML later.
Code:
var document = new Aspose.Words.Document(@".\test.docx");
document.LayoutOptions.TextShaperFactory = HarfBuzzTextShaperFactory.Instance;
document.Save(@".\test.html");
image.png (45.6 KB)
test.zip (80.8 KB)
Thanks,
@ServerSide527 You can make Aspose.Words to write style from MS Word document as css class by setting CssStyleSheetType.Embedded
. In this case test
style is exported as the following:
.test { margin-bottom:0pt; line-height:normal; font-family:Verdana; font-size:12pt; font-weight:bold; font-style:italic }
See the following code:
Document doc = new Document(@"C:\Temp\test.docx");
HtmlSaveOptions opt = new HtmlSaveOptions();
opt.CssStyleSheetType = CssStyleSheetType.Embedded;
opt.PrettyFormat = true;
doc.Save(@"C:\Temp\out.html", opt);
Is this what you are looking for?
Hi @alexey.noskov
Thanks, we’ll keep that suggestion for other things in the future. However, our system needs it inline.
Can you please have a look and make the font-size appear in line as well as it should?
Thanks,
@ServerSide527 Thank you for additional information. The issue has been logged as WORDSNET-23701. We will keep you informed and let you know once it is resolved or we have information for you.
@ServerSide527 We have completed the analysis of this issue. It is scheduled to be resolved before 22.7 (July 2022) release.
When a HTML document is rendered in quirks mode, the style table { font-size: initial }
is applied by browsers (see https://html.spec.whatwg.org/multipage/rendering.html#tables-2). Aspose.Words doesn’t write "font-size: 12pt"
on paragraphs inside the table, because it sees that the same style is inherited from the parent table element. However, since the inherited value is the default font size from the user agent stylesheet, it should should be written anyway, because default font size and font family can easily be changed in browsers.
As a workaround, you can save HTML documents with HtmlSaveOptions.HtmlVersion = HtmlVersion.Html5
or HtmlSaveOptions.ExportXhtmlTransitional = true
. Any of those values will instruct Aspose.Words to write a DOCTYPE declaration to HTML that will make it a “standards mode” document. Aspose.Words will write “font-size” styles to paragraphs in tables, because the rule that resets table font size to the default value is not applied in the “standards mode”.
1 Like
The issues you have found earlier (filed as WORDSNET-23701) have been fixed in this Aspose.Words for .NET 22.7 update also available on NuGet.
A post was split to a new topic: Font attributes missing in HTML