0

Given an HTML page source code, i would like to know how to detect whether there is enough space to print the given content.

So far what i do is:

This is my controller:

function viewer($mode = NULL){
        $this->load->helper(array('pdf', 'file'));

        $html = $this->load->view('form/document.pdf.php', '',TRUE);
        pdf_create($html, 'ABC_'.time());
}

$html is just a plain HTML document, nothing fancy there.

How can i know if the given $html should fit one, two or more A4 pages ?

Jeremy
  • 2,516
  • 8
  • 46
  • 80
  • You can't. HTML is a screen-oriented format and not a paper-oriented format. – GordonM Sep 08 '14 at 06:53
  • Maybe you can by getting the height of the body and with some trial and error. – Traian Tatic Sep 08 '14 at 07:01
  • @TraianTatic i assume some javascript involved... Anyway i am still looking for the best way to do it. – Jeremy Sep 08 '14 at 07:07
  • 1
    Well, saying you can't is somewhat blunt, because you can. A good way to this would be: Create a PDF out of the HTML, like in your example, and see how many pages long it is. PDF's are paper-oriented and will therefore tell you how many pages will be used when it is printed. – KIKO Software Sep 08 '14 at 07:50
  • I have just been contemplating the same issue; as a client wants to have headers duplicated where the content is too long for a page. But as the page to PHP is just pure dimension-less html, it is not possible. However best practices would mean that every x amount of rows table headers are repeated, and that images are max-height and width constrained so they don't blow it out. – Onyx Sep 10 '14 at 02:12
  • @Onyx What i need (and i think the same goes to you) is essentially a text editor like what is being used in Google Docs (http://googledocs.blogspot.com/2010/05/whats-different-about-new-google-docs.html), if only they made it opensource.... – Jeremy Sep 10 '14 at 09:22

0 Answers0