I am trying to generate a pdf from the html content which has been entered using the mpdf library.

Is there any possibilities of limiting the number of pages. For example: I want only two pages not more than that.

有帮助吗?

解决方案 2

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.

其他提示

I suppose you can override mpdf class addPage method, and if the number of pages is more then you want, generate EnoughPagesException, catch it up in your code, and there you have the mpdf object with the number of pages you need.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top