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

Free Support Forum - aspose.com

Insert HTML with custom page number into document using .NET

Hi, I need to add the page number on each page’s footer, the problem here is how can I give some formatting using HTML? for example I am looking to apply this on the footer but to achieve that I need that $$Page is a wildcard on aspose.words or something like that, is that possible? Here is the sample html that I would like to insert on my footer:

<div style='font-size:12pt;font-family:Verdana;'>

<p><u><i><b>Page <span style='color:#e74c3c;'>$$PAGE</span></b></i></u></p>

<p style='text-align: right;'>$$NUMPAGES</p>

<p style='text-align: right;'>$$TIME</p>
</div>

as you can see I have the word Page before the current page number wildcard that should be applied on each page. how can I achieve this?

Thanks, regards.

@maik1

You can insert HTML into Word document using DocumentBuilder.InsertHtml method. If you want to insert HTML with PAGE and NUMPAGES fields, you can insert HTML snippet as shown below.

<div style="-aw-sdt-tag:''">
	<p style="margin-top:0pt; margin-bottom:0pt; font-size:12pt">
		<span style="-aw-field-start:true"></span><span style="-aw-field-code:' PAGE   \\* MERGEFORMAT '"></span><span style="-aw-field-separator:true"></span><span style="font-family:'Times New Roman'">1</span><span style="-aw-field-end:true"></span>
	</p>
	<p style="margin-top:0pt; margin-bottom:0pt; font-size:12pt">
		<span style="-aw-field-start:true"></span><span style="-aw-field-code:' NUMPAGES   \\* MERGEFORMAT '"></span><span style="-aw-field-separator:true"></span><span style="font-family:'Times New Roman'">1</span><span style="-aw-field-end:true"></span>
	</p>
</div>

You may also insert your shared HTML into Word document and use find and replace feature to replace the text with PAGE and NUMPAGES fields. Please read the following articles.
Find and Replace
Working with Fields

is it possible that the snippet can automatically enumerate word pages alone instead of me coding it doing a for each page? @tahir.manzoor I mean something like this:

dBuilder.InsertField("<div style='font-size:12pt;font-family:Verdana;'><p style='text-align: right;'>{{PAGE}}</p></div>");
where {{PAGE}} is the field that aspose.words will be replacing with proper page number on each page, can that be achieved? or should I need to code this for each page and setting the right counter number per page?

Thanks in advance

@tahir.manzoor forget my previous message, I got working the code snippet you shared originally, that is what I was looking for! thanks a lot! :slight_smile:

@maik1

It is nice to hear from you that your problem has been solved. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.