Well, I spent the whole day or so figuring this out, so I wanted to post my decision on this if someone else needs an answer.
So here's what I did.
- Generated output as usual (not for printer)
- 2 stylesheets have been created (one for the printer and one for the screen). Measurements were taken in inches (not pixels) for all page elements that should be converted to a printed result.
- Using jQuery, I did the following:
-> a called function that adds the original page to the DOM - something like this
// assumes old_page_id is existing element in DOM, and var page_id = 1; $j("<div class='page' id='" + page_id + "'><div class='print_area'></div></div>") .insertAfter('#' + old_page_id);
-> measure the height of the div, which is the page (in my case, $ ('. page'). height ();)
-> launches a function to insert div and new pages - something like this
$('div_class').each( function() { // measure height of $(this) // add it to running total of used space on existing page // if sum total exceeds remaining space, create new page, and add to that one // if still room left, add to this one } );
Note that each page div (in my case, class = 'page') in the printer style sheet has the following:
page-break-after: always;
This is how I got it to create a new page on the printer where I wanted.
After running the jQuery function above, I hid the original section containing the div elements that I wanted to move to the printed pages. Note. I could not hide this section until my jQuery measurements yielded acceptable results (in my case, I placed the entire div in the wrapper div with the id " hide_me " and set the style to height: 1px; overflow: auto; ).
I understand that it is very 50,000 feet, but I hope it is useful to you.
Onenerd
source share