Font Size in HTML not Reflected and Zoom Level

Hi,
We have been using Aspose.words for manipulating word documents.
While inserting header in the form of html, the font size in the tag is not reflected in the resultant document.
If we specify as then by default it is taking as 10px
If we set as then it is taking as 36px.
Coding we used for header insertion

var docBuilder = new DocumentBuilder(doc);
docBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
docBuilder.InsertHtml(headerContent);

Please let us know your views on this.
Further we don’t want to use HandleNodeChanging_FontChanger, we want this size setting in html level only.

Another Query is that, how to set zoom level for the word document, while building the document.
Please check the attachment for the zoom level which I am specifying.

Thanks,
Nandha Kumar Arulanandam.

Hi Nandha,

Thanks for your inquiry. Could you please attach your input Html file here for testing? I will investigate the issue on my side and provide you more information.

Secondly, you can use the following code to make sure the document is displayed at 75% zoom when opened in Microsoft Word.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("hello world");
doc.ViewOptions.ViewType = ViewType.PageLayout;
doc.ViewOptions.ZoomPercent = 75;
doc.Save(@"C:\Temp\out.doc");

I hope, this helps.

Best regards,

Hi Awais Hafeez,

Thanks for the zoom percentage settings.
Please find the attached html file, which we have used for inserting header content.

Further we need to “remove space after paragraph” in the inserted header html content.

Thanks,
Nandha Kumar Arulanandam.

Hi Nandha,

Thanks for your inquiry.

Please note that Aspose.Words’ HTML engine tries to mimic the way the Microsoft Word works. To you, this means that if you export your HTML to a Microsoft Word document using Aspose.Words, the output will appear almost exactly as if it was done by Microsoft Word. Moreover, I have attached two DOCX documents (one generated by Aspose.Words and the other generated by Microsoft Word) here for your reference. You can observe the font sizes of content in both DOCX files being identical.

Secondly, the extra vertical space in header is caused by an empty Paragraph; you can remove this last Paragraph from the header by using the following code snippet. I hope, this helps.

string htmlString = File.ReadAllText(@"C:\header\header.htm");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertHtml(htmlString);
builder.CurrentParagraph.Remove();
doc.Save(@"C:\header\out 13.2.0.docx");

If we can help you with anything else, please feel free to ask.

Best regards,

Hi Awais Hafeez,

Thanks for the help.

As per your suggestion we have tried using

builder.CurrentParagraph.Remove();

as follows

docBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
docBuilder.InsertHtml(headerhtml);
docBuilder.CurrentParagraph.Remove();

docBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
docBuilder.InsertHtml(headerhtml);
docBuilder.CurrentParagraph.Remove();

In the above highlighted line “Object reference not set to instance of an object” error but if it is used as below

docBuilder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
docBuilder.InsertHtml(headerhtml);

docBuilder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
docBuilder.InsertHtml(headerhtml);
docBuilder.CurrentParagraph.Remove();

i.e., removing the current paragraph after header and footer then no exception occurs, but the header section has one extract line after header content.

Aspose.words version used : 10.3.0.0

Can you please help with this quickly ?

Regards,
Nandha Kumar Arulanandam.

Hi Nandha,

Thanks for the additional information. There are different ways you can remove last empty Paragraph from the end of header/footer. For example, please see the following code snippet:

string htmlString = File.ReadAllText(@"C:\header\header.htm");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertHtml(htmlString);
Paragraph lastPara = doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].LastParagraph;
if (lastPara != null)
    if (lastPara.ChildNodes.Count == 0)
        lastPara.Remove();
doc.Save(@"C:\header\out.docx");

In the attached screenshot, you can see the DOM structure of my test document when viewed with Document Explorer. DocumentExplorer is a very useful tool which easily enables seeing the entire document structure. You can find DocumentExplorer in the folder where you installed Aspose.Words e.g. C:\Program Files (x86)\Aspose\Aspose.Words for .NET\Demos\CSharp\DocumentExplorer\bin\DocumentExplorer.exe. You can view the structure of documents by opening them with DocumentExplorer.
https://docs.aspose.com/words/net/aspose-words-document-object-model/

Please let me know if I can be of any further assistance.

Best regards,