forcing page breaks

1,917 views
Skip to first unread message

Tom Hoffman

unread,
Sep 21, 2009, 2:05:00 PM9/21/09
to sphin...@googlegroups.com
Hi all,

Is there any way to force page breaks in pdf generation?

--Tom

Roberto Alsina

unread,
Sep 21, 2009, 2:45:55 PM9/21/09
to sphin...@googlegroups.com
On Monday 21 September 2009 15:05:00 Tom Hoffman wrote:
> Hi all,
>
> Is there any way to force page breaks in pdf generation?

Via latex or via rst2pdf?

--
("\''/").__..-''"`-. . Roberto Alsina
`9_ 9 ) `-. ( ).`-._.`) KDE Developer (MFCH)
(_Y_.)' ._ ) `._`. " -.-' http://lateral.netmanagers.com.ar
_..`-'_..-_/ /-'_.' The 6,855th most popular site of Slovenia
(l)-'' ((i).' ((!.' according to alexa.com (27/5/2007)

MishaS

unread,
Sep 21, 2009, 3:39:22 PM9/21/09
to sphinx-dev
On Sep 21, 9:45 pm, Roberto Alsina <rals...@netmanagers.com.ar> wrote:
> On Monday 21 September 2009 15:05:00 Tom Hoffman wrote:
> > Is there any way to force page breaks in pdf generation?
> Via latex or via rst2pdf?
My take is: via rst2pdf :)) I'm actually missing page breaks before
sections... :-/

--
Misha

Tom Hoffman

unread,
Sep 21, 2009, 3:52:17 PM9/21/09
to sphin...@googlegroups.com
On Mon, Sep 21, 2009 at 2:45 PM, Roberto Alsina
<ral...@netmanagers.com.ar> wrote:
>
> On Monday 21 September 2009 15:05:00 Tom Hoffman wrote:
>> Hi all,
>>
>> Is there any way to force page breaks in pdf generation?
>
> Via latex or via rst2pdf?

Well... just generally inserting page breaks in my Sphinx scripts. I
don't have any preference regarding the specific technique.

--Tom

Roberto Alsina

unread,
Sep 21, 2009, 7:08:35 PM9/21/09
to sphin...@googlegroups.com

Oh, that's easy ;-)

In your conf.py, add

pdf_break_level = 1

And you get pagebreaks in top-level sections, 2 for breaks on subsections, and
so on.

You may also want to add

pdf_breakside = "odd"

or "even" or "any".

Best regards,

Roberto Alsina

unread,
Sep 21, 2009, 7:09:42 PM9/21/09
to sphin...@googlegroups.com

They are builder-specific, I think. For example, for HTML they make no sense.

For rst2pdf:

.. raw:: pdf

PageBreak

Max Battcher

unread,
Sep 21, 2009, 7:35:54 PM9/21/09
to sphin...@googlegroups.com
Roberto Alsina wrote:
> On Monday 21 September 2009 16:52:17 Tom Hoffman wrote:
>> On Mon, Sep 21, 2009 at 2:45 PM, Roberto Alsina
>>
>> <ral...@netmanagers.com.ar> wrote:
>>> On Monday 21 September 2009 15:05:00 Tom Hoffman wrote:
>>>> Hi all,
>>>>
>>>> Is there any way to force page breaks in pdf generation?
>>> Via latex or via rst2pdf?
>> Well... just generally inserting page breaks in my Sphinx scripts. I
>> don't have any preference regarding the specific technique.
>
> They are builder-specific, I think. For example, for HTML they make no sense.

There are CSS print styles to affect HTML print documents. Untested example:

.. raw:: html

<br style="page-break-after: always" />

Another approach might be:

.. cssclass:: pagebreak

Paragraph or section or whatever...

Then add to the stylesheet:

.pagebreak { page-break-before: always }

--
--Max Battcher--
http://worldmaker.net

Guenter Milde

unread,
Sep 22, 2009, 3:32:02 AM9/22/09
to sphin...@googlegroups.com

* There is no generally supported page-break element in the
reStructuredText markup language.

* You can configure page-breaks at certain elements (e.g. before level-1
sections) in the custom style sheets.

Custom style sheets are writer dependent, so it matters, whether you
use rst2latex, rst2newlatex, or the rst2pdf extension.

With rst2latex:

* Page breaks before top-level sections are the default with a
documentclass that provides "chapters", e.g. "book", "memoir" or
"scrbook".

* Redefining the \section or \section* command in a
style sheet is possible too.

* `Raw latex` can be used::

.. raw:: latex

\newpage % hard pagebreak at exactly this position

or

.. raw:: latex

\pagebreak[2] % recommended page break after line end (precedence 1...4)

* The transition element can be re-defined to produce a page break,
e.g.

in a style sheet::

\newcommand*{\DUtransition}{\pagebreak[4]}

or in the document::

.. raw:: latex

\renewcommand*{\DUtransition}{\pagebreak[4]}


(The redefining of the transition element requires a recent snapshot of
the Docutils and might not (yet) work with Sphinx.)

Günter

Max Battcher

unread,
Sep 22, 2009, 3:47:34 AM9/22/09
to sphin...@googlegroups.com
On 9/21/2009 19:35, Max Battcher wrote:
> .. cssclass:: pagebreak

Or just .. class:: once the code directive renaming takes place, of course.

> Paragraph or section or whatever...
>
> Then add to the stylesheet:
>
> .pagebreak { page-break-before: always }

Following this approach to its logical conclusion... Would it make sense
to standardize on a class name here and then encourage all of the Sphinx
builders that have some sort of print form to look for a standard class
name and always page break before/after items tagged with it? (That is,
make it a part of the default stylesheets of as many builders as possible.)

It seems to me that a generic class that most or even all builders
respond to for "forcing" page breaks in print layouts might be handy to
have (and to document having).

Guenter Milde

unread,
Sep 22, 2009, 6:24:28 AM9/22/09
to sphin...@googlegroups.com

>> .pagebreak { page-break-before: always }

Sensible idea. Could you file it at as a feature request to the Docutils
tracker http://sourceforge.net/tracker/?group_id=38414&atid=422033
please? This way it will be remembered.

Günter

Reply all
Reply to author
Forward
0 new messages