We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Empty paragraph is added after inserting HTML into header of document using C#

I am building header with html to word. It’s adding extra blank line at the end of the header.
Is there any settings to remove the blank line from the header.

@ShivaShanker

The extra line is empty paragraph. You can remove it using Node.Remove method.

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a standalone console application ( source code without compilation errors ) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Tahir,

Here are some details about the issue. Decode the string below with Base64 decode that gives html and convert the html below into document header part, which is adding space at the end. The issue because of h1, and p tags but can’t eliminate them. Let me know if there is any solution can that can work without altering the content below.

PGJvZHk+CjxoMT48aW1nIHNyYz0iaHR0cHM6Ly93d3cudzNzY2hvb2xzLmNvbS9pbWFnZXMvcGljdHVyZS5qcGciIGFsdD0iTG9nb18yLmdpZiIgd2lkdGg9Ijk5IiBoZWlnaHQ9IjQ0Ij48L2gxPiAKPHA+Rm9yIFRlc3Rpbmc8L3A+CjwvYm9keT4=

@ShivaShanker

You can remove the last line of header using the Node.Remove method. Please check the following code example.

var doc = new Document();
var builder = new DocumentBuilder(doc);
                
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertHtml(File.ReadAllText(@"C:\input.html"));
doc.FirstSection.HeadersFooters[HeaderFooterType.HeaderPrimary].LastChild.Remove(); 
                
doc.Save(MyDir + "20.3.docx");

thanks, Tahir.