Search code examples
phpruby-on-railscontent-management-systemserver-side

How could a cms application split content over multiple pages?


I have an idea for a website that involves content being split over multiple pages. Similar to this:

http://tympanus.net/Development/3DBookShowcase/

However, I have no idea how I could work out how to split this content, aside from using a monospaced font, working out how many words there are per page and diving the total number of words by page number.

However, I'd like to use a different number of fonts, insert images and diagrams. I'm currently thinking that something that dynamically finds out the widths of each font character and then counts each character per page and from there works out how to split them. That's getting a bit bad though.

How does a Word Processor know how to split pages, and could this realistically be replicated using PHP or Ruby on Rails or some other server-side language?


Solution

  • In terms of rendering to different pages, it's not a trivial task. For a CMS, if your content is book-length, I certainly would look into pre-processing this: so that each page is stored separately, and so you don't have to do any calculations to determine where each pages starts inside your content HTML.

    However, that might cause problems with sentences that wrap from one page to the next: because of pixel differences, the split point may vary from browser to browser, depending on page size, fonts installed, complexity of markup, and so on. Browsers were never intended to hold paginated data, though I believe they are getting slightly better (in terms of CSS support).

    There might be other complex wrapping issues as well, depending on your content. In any case, I wouldn't try measuring font widths server-side and using that to decide split points, since HTML/CSS rendering is very complicated. There might be some mileage in using JavaScript for this, though - you can see where a particular browser has split across pages, and then start at the next word for the next page.

    It would be a great deal easier for you if you could render all your pages to PDF, and then load them on demand, embedded as an object. You'd have to determine what your trade-off is with accessibility issues, to see if this is a road you wanted to go down.