HTML to PDF : Get pages number

Hello,

I want to know if there is a method in ASPOSE API which permit to get the total number of the pages by using only the HTML without converting it to PDF?

Thank you very much for your response.

@matmut

Thank you for contacting support.

We are afraid that currently there is not any method or property that can be used to get number of pages without converting the HTML file. However, a ticket with ID HTMLNET-1351 has been logged as a feature request for Aspose.HTML for .NET API. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.

In c#, try using setFooterHtml ::

client.setFooterHtml(“Page %p of %n”);

Please note that the %p variable is not expanded in a string passed to convertHtml(). It is expanded only in these functions: setFooterHtml(), setFooterUrl(), setHeaderHtml(), and setHeaderUrl().

@matmut
@Sherin_Mathew

Thank you for your valuable contribution.

Moreover, about HTMLNET-1351 we would like to update that there is no quick way to get the total number of the pages without printing document, because it depends on the printing setting such as page size and margins of the page, besides that we need to load the font metrics to calculate the size of the every glyph of the document. So, to get the total number of the pages we need to perform the full printing of the document.
But, it is not necessary to print your HTML document to PDF and load PDF to count total pages. Below is a much easier way by counting pages during rendering process:

/// 
/// The rendering-device extension class that allows to count the page numbers
/// 
class PdfDeviceExtended : PdfDevice
{
public PdfDeviceExtended(string file) 
: base(file)
{
}

public override void BeginPage(SizeF size)
{
    PageCount++;
    base.BeginPage(size);
}

public int PageCount { get; private set; }
}
// Usage example
using (var document = new HTMLDocument())
using (var device = new PdfDeviceExtended("out.pdf"))
{
document.RenderTo(device);
}

We hope this will be helpful. Please feel free to contact us if you need any further assistance.