Creating & balancing text columns
| From: | Miles Thompson | Date: | Sat, 10 May 2003 01:59:17 +0000 |
| Subject: | Creating & balancing text columns | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-147086@lists.php.net to get a copy of this message | ||
We're just about at the end of the development cycle for a news site, Articles are stored in a database, fetched through a PHP script and displayed through a Flash movie. A small percentage of customers prefer a printed version. For how we got this far, see note(1).
Flash absolutely sucks at printing. So we're taking an alternate approach, using a small, chromeless browser window with selection & right click turned off, insofar as this is possible. When the window loads JavaScript is used to invoke the print dialog. The purpose of all this is to mitigate a "pass around without paying for it" problem.
Here's the challenge - does anyone know how to balance the printed columns?
Presently I get the length of the article, roughly divide it in two, search for a space and decide that's where the column break will be. Each column is then dumped into a table cell. As long as the writing and paragraph length is reasonably consistent, the results are remarkably good - maybe a 2~4 line discrepancy.
The problem is that if the story breaks across a page, you have to read the first column, go to the next page and read to the end of that column, then turn back to the previous page and read down the second column to the end of the story. Not exactly intuitive.
Now the output device is a browser, and no matter what formatting instruction I've issued, the user can over-ride them. I've thought of getting very particular - determining a line count for a "typical" page, maintaining a line counter, creating an array of lines, formatting each line for length before placing it in the array, and then divvying up the array between the column-lines available or remaining on a given page, and allocating the remainder on the following page. (Sure reminds me of complex FoxPro reports about 13 yr ago!)
The "page" of course doesn't exist, because output is going to the browser, which determines what it's page is.
Yes, what we're attempting is a crude, auto-running, Adobe Pagemaker-like operation in PHP.
Is there a better way? The other option is to let it run in all it's bug-ugliness, running the copy full width across the page as we did when typing out term papers, essays and the like when a correcting Selectric was the hottest thing going.
Regards - Miles Thompson
(1) In case you are wondering, we've tried password protecting the site and using straight HTML, password protecting and auto-downloading .pdf files, and direct mailing of .pdf files to subscribers.
The first resulted in sharing of passwords - we're going to start limiting the number of logins each week.
The second we coped with by allowing a user to login once, then setting a cookie on the browser, storing its value in the database and setting a "logged in" flag. If a login from another browser, even on the same machine, was attempted, it would fail. This was not a really popular solution, and the .pdf could be forwarded to a "friends of the subscriber" list. There were also download problems with IE 5.5.
The third is most straightforward, but relies entirely on the honour system and there is a significant level of "pass around" of the .pdf's. /mt