dhcrusoe Posted January 29, 2009 Share Posted January 29, 2009 Hey there, We have a pretty specific challenge & would love thoughts about how to overcome. The challenge is that we have several web pages of unknown length, and need to calculate how many printable pages they will result in if printed. We calculate that each printable page can contain about 600 vertical pixels of content. Does anyone have any idea of how to construct a function that would tell us how many printable pages an html page might be (if run through the function) and/or a way to show thumbnails thereof? Or any good starting points - those would be great as well! Thanks for any insights you have! --Dave / Public Learning Media Labs Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/ Share on other sites More sharing options...
Mchl Posted January 29, 2009 Share Posted January 29, 2009 Since it is the user's browser that decides what size the content will be, and also his printer drivers that decide what can fit onto one page, this is pretty much impossible to do in reliable way. Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-749917 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 just make all pages needed printer friendly. <link href="/css/screen.css" rel="stylesheet" media="screen" type="text/css" id="screencss" /> <link href="/css/print.css" rel="stylesheet" media="print" type="text/css" id="printcss" /> //And use this javascript to toggle: function togglecss() { var screencss = document.getElementById('screencss'); var printcss = document.getElementById('printcss'); if (screencss.flag == true) { screencss.href = screencss.oldhref; screencss.flag = false; //alert('When you are done printing, just click the \'printer Friendly\' link again.'); } else { screencss.oldhref = screencss.href; screencss.href = printcss.href; screencss.flag = true; } } //And a link like so: <a href="#" onclick="togglecss();return false;">printer Friendly</a> Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-749926 Share on other sites More sharing options...
dhcrusoe Posted January 29, 2009 Author Share Posted January 29, 2009 What if we were able to set the screen as a certain number of pixels, e.g., 600 deep? It turns out that we don't have control over the CSS or HTML of the page we want to paginate. --Dave Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750038 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 read mchi reply agin. why are you driving your self mad about this please. can you imagine the amount off printer drivers your need to collect, and understand to accomplish this m8. be imposable m8. Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750045 Share on other sites More sharing options...
DarkSuperHero Posted January 29, 2009 Share Posted January 29, 2009 so are you trying to calculate the prinable pages from an external website...eg yahoo.com or msn.com ect.... Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750050 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 He wants us to find the begging of a webpage to the end of a web page, then he wants to calculate. how many pages the web page would take to print to a printer. but there no real way in doing that because everybody got different printer drivers to print pages. also will the user care how long the page's are. when you print a document the printer driver tills you how many pages there are to be printed. you don't tell it. the only way you could do this if it a dedicated printer and computer and only that printer is printing the web pages in question. but saying that you got me thinking, maybe a big maybe you can use exec to open the file tab on a browser then exec print preview then get that info to the user maybe. big project and time theo. Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750073 Share on other sites More sharing options...
dhcrusoe Posted January 29, 2009 Author Share Posted January 29, 2009 Hey Guys, Yep, I know. But imagine if you could create a low-rez pdf of the page - actually, maybe that's the way to do it? run a script to convert the page to PDF, and then count PDF pages? Would that be possible? --Dave He wants us to find the begging of a webpage to the end of a web page, then he wants to calculate. how many pages the web page would take to print to a printer. but there no real way in doing that because everybody got different printer drivers to print pages. also will the user care how long the page's are. when you print a document the printer driver tills you how many pages there are to be printed. you dont tell it. Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750080 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 this will get the print preview i think sorry long time use javascript. <a href="javascript:void(0);" onclick="displayHTML(document.getElementById('printarea').innerHTML)">Print Preview</a> Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750109 Share on other sites More sharing options...
DarkSuperHero Posted January 29, 2009 Share Posted January 29, 2009 sounds like a great idea dhcrusoe, i think it would def get the job done! :-) http://www.rustyparts.com/pdf.php http://www.digitaljunkies.ca/dompdf/ there plenty of html to pdf scripts out there... i haven't ever needed one so i don't know which one is best... Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750118 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 ie only print preview <html> <head> <title>Print Preview</title> <script> function printpr() { var OLECMDID = 7; /* OLECMDID values: * 6 - print * 7 - print preview * 1 - open window * 4 - Save As */ var PROMPT = 1; // 2 DONTPROMPTUSER var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>'; document.body.insertAdjacentHTML('beforeEnd', WebBrowser); WebBrowser1.ExecWB(OLECMDID, PROMPT); WebBrowser1.outerHTML = ""; } </script> </head> <body> <form> <input type='button' value="Print Preview" onclick="printpr();"> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/143012-php-to-calculate-the-number-of-printable-pages-from-html/#findComment-750124 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.