You don't have to specify the maximum number of pages, you simply add a fixed maximum number of pages programmatically after having set the page size.
$mpdf = new mPDF('utf-8', 'A4');
so now you have A4 pages, now you add the specified number of pages.
If instead you want to use html as a long line of text
$mpdf->WriteHTML('<div id="text"><p>Bla bla</p></div>', 2);
you might need to measure somehow how long your html is based on the page format, that might not be as easy as it sounds.