5

I am using mPDF to generate PDF files from form submissions. The script is going through all questions and creating a HTML fieldset for each containing the question and the answers.

Since the survey is quite long, the generated PDF spans over several pages which works fine. Now, the client wants "nice & pretty" PDF files, where a fieldset does not contain a page break.

From this question, I know I can determine the remaining space of a page during the generation process.

Now the question is, how can I determine the height of the fieldset coming up next in order to decide whether or not I have to add a page break first? Is there a function, which just renders a specific part of HTML as a PDF and returns the final height?

Community
  • 1
  • 1
Paul
  • 8,974
  • 3
  • 28
  • 48
  • Have you already found a solution? – bernhardh Oct 05 '16 at 14:16
  • 1
    @leftjustified Not a satisfying one, this is, I am not using some mPDF functions. I ended up writing my own estimation script. It calculates the height of a fieldset based on the question and answer texts (length ~= number of lines), using pre-defined margins, font-sizes and other metrics. Testing through literally hundreds of options, I was able to refine the script to work just fine with my special case. Sadly, it's not an one-fits-all solution. – Paul Oct 06 '16 at 06:04
  • Thank you for your reply. I think another solution is to DeepCopy the actual mpdf-object (for example with https://github.com/myclabs/DeepCopy), add the element and then compare the two '$mpdf->h' heights. Not really nice or performant solution, but it can work. – bernhardh Oct 06 '16 at 13:07
  • has anyone found solution yet? – Niran Manandhar Dec 12 '17 at 01:47

0 Answers0