[FM Discuss] coolest hack in a while

adam hyde adam at flossmanuals.net
Wed Jan 12 07:04:31 PST 2011


hi,

so after some complaining to the fm dev team (they never listen unless i
complain) Aco come up with a *very* nice hack for helping create the
book formatted pdf. actually it was an idea doug had some time ago but
Doug has just become a dad again and so he has been understandably
otherwise occupied :)

so...the issue was that objavi (the pdf generator) has no control over
widows and orphans or and page-break-after:avoid does not work for
heading tags...what does this mean? it means that if you have a heading
and a paragraph that follows it we have no way of ensuring that the
heading and the paragraph will be on the same page. it might occur,
through luck and bad management, that the heading is at the bottom of a
page and the following paragraph is on the next page. 

eg..

<p> some text...</p>
<h2>the next thing</h2>
-----page break-----
<p>para about the next thing</p>


in a book this looks *ugly*

we can manage this manually. by using the editor and inserting page
breaks. this inserts a div tag with id=PageBreak and hence we use css to
force a page break at that point. We would use this in the css:

div#PageBreak {
  height:0px !important;
}

the problem here is that when u change the output format (say from A5 to
A4) you need to change all these pagebreaks manually. This is really not
cool.

so, now with the hack every h2,h3 and h4 tag has a div wrapped around it
and the paragraph that follows. You dont see this - it happens server
side when the pdf is generated. If you then use this css (which will be
in the default style sheet shortly):

div#keeptogether {page-break-inside:avoid;}

then the headings stick to the paragraphs. So a heading that would fall
to the bottom of a page with the paragraph after it starting at the top
of the next page would be put on the next page - so the heading and
paragraph stay together.

using the above example...we would now get this:

<p> some text...</p>
-----page break-----
<h2>the next thing</h2>
<p>para about the next thing</p>


this is *very* cool. of course you dont have to use this. you can still
do it all manually if you want extra control in specific
situations...but this is a very good fix....

adam





-- 
vote for booki in the Open Web Awards!

Booki (the latest FM project - http://www.booki.cc - a collaborative
publishing platform) is in the final of the Open Web Awards.
Great! We are 1 of 3 projects. If we win we get 5000 which we will use
to do a code sprint on a tropical island somewhere ;)

please please please register :
http://www.drumbeat.org/user/register

and vote for us by visiting this page and clicking on the 'vote' link (top right):
http://www.drumbeat.org/project/open-web-publishing

and pass this around!!!! :)

Adam Hyde
Founder FLOSS Manuals &
Booki Project Manager 

Contact Information
German mobile : + 49 177 4935122
Email : adam at flossmanuals.net
irc : irc.freenode.net #flossmanuals


"Free manuals for free software"
http://www.flossmanuals.net/about

Free Software for making Free Books
http://www.booki.cc/




More information about the Discuss mailing list