Switching Stylesheets

109 views
Skip to first unread message

Mike Driscoll

unread,
Apr 7, 2014, 9:45:23 AM4/7/14
to rst2pdf...@googlegroups.com
Hi,

I have discovered that I need a way to switch stylesheets in my document. Some pages require my images to be full page with no headers while the normal pages need regular margins. I can't seem to find any examples on how to specify a stylesheet in RST itself. Instead, the examples seem to be all passing a stylesheet on the command line, which isn't going to work for me.

Can anyone point me to an example or at least some documentation on the matter?

Thanks,
Mike

Roberto Alsina

unread,
Apr 7, 2014, 11:02:07 AM4/7/14
to rst2pdf...@googlegroups.com
You don't need to switch stylesheets for that. One stylesheet can define multiple page layouts, and you can switch from one to the other using raw and Pagebreak (they are in the manual)


--
You received this message because you are subscribed to the Google Groups "rst2pdf-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rst2pdf-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Purcell

unread,
Apr 7, 2014, 11:17:36 AM4/7/14
to rst2pdf...@googlegroups.com
Here's an example.

In my stylesheet the initial template to be used is defined as one named "oneColumn":


    firstTemplate: oneColumn

Then, the "oneColumn" template is defined to show headers/footers:

  pageTemplates:
    oneColumn:
        frames: []
            [0cm, 0cm, 100%, 100%]
        showHeader : true
        showFooter : true

And a second template is defined to NOT show headers/footers:

    secondPage:
        frames: []
            [0cm, 0cm, 100%, 100%]
        showHeader : false
        showFooter : false




Then, in my main document, at the end of my first page, I insert this:


.. raw:: pdf
    PageBreak secondPage


Works perfectly for me.

Hope that helps.

Scott

Mike Driscoll

unread,
Apr 7, 2014, 12:29:43 PM4/7/14
to rst2pdf...@googlegroups.com
This does sound promising. I guess the next question is where do I put the stylesheet and what do I call it?

Thanks,
Mike

Scott Purcell

unread,
Apr 7, 2014, 5:44:02 PM4/7/14
to rst2pdf...@googlegroups.com
Wherever you like and whatever you like.  I use the following script, executed through a keystroke shortcut from within my editor (gedit):

#!/bin/sh
SRCNAME="$GEDIT_CURRENT_DOCUMENT_PATH"
TMPNAME="$(echo $SRCNAME | sed s/.rst.txt//)"
DSTNAME="${TMPNAME}.pdf"
if [ -e ${TMPNAME}.style ] ; then STYLENAME="${TMPNAME}.style"
    else STYLENAME=".template_includes/template.style"
fi    
rst2pdf  "${SRCNAME}"  --strip-elements-with-class=instructorsonly --strip-elements-with-class=slidesonly --smart-quotes 2 -b 0 -s "${STYLENAME}" -o "${DSTNAME}" 
nohup evince "${DSTNAME}" &

It first looks, in the same directory as the source file, for a file with the same basename but a .style extension.
If that doesn't exist, it uses a default style in a templates directory.





Mike Driscoll

unread,
Apr 8, 2014, 9:37:51 AM4/8/14
to rst2pdf...@googlegroups.com
What does the frames part do?


frames: []
       [0cm, 0cm, 100%, 100%]

I looked at the default stylesheet and according to the comments, I can't change the margins unless I include other stylesheets, but Roberto said I didn't need to switch stylesheets to do that so I'm getting a bit confused.

- Mike

Scott Purcell

unread,
Apr 8, 2014, 10:32:03 AM4/8/14
to rst2pdf...@googlegroups.com
I believe it defines the part of the page to be used for text columns.  Here's an example of its use to create 2 column and 3 column layouts:


    twoColumn:
        frames: []
            [0cm, 0cm, 49%, 100%]
            [51%, 0cm, 49%, 100%]
        showHeader : true
        showFooter : true

    threeColumn:
        frames: []
            [2%, 0cm, 29.333%, 100%]
            [35.333%, 0cm, 29.333%, 100%]
            [68.666%, 0cm, 29.333%, 100%]
        showHeader : true
        showFooter : true


Here's a document where I did what it sounds like you're trying to do (have the first page print the header/footer, and subsequent pages omit them).  I obfuscated the text, but you can see that the first pages has a header (the line with the logo) 

Inline image 1
The next page does not print the header.Inline image 2
To my eye, it does not look unbalanced to have the same top margin in both cases... but then, our header is not too large.

Mike Driscoll

unread,
Apr 8, 2014, 1:50:29 PM4/8/14
to rst2pdf...@googlegroups.com
I think I must have explained myself poorly. I am writing a book. The cover of the book is an image that I would like to have cover the entire first page (all 8.5 x 11 inches of it) with no header/footer. The next 50 or so pages are book content that will have a header/footer. Then there will be another full page image to demarcate the next section of the book. That's where I'm getting hung up. When I try to place my cover image, it has an inch margin on every side, which looks really odd. So I need to find a way to remove the margins and headers on certain pages and then re-add them.

Does that make sense?

- Mike

Roberto Alsina

unread,
Apr 8, 2014, 2:02:16 PM4/8/14
to rst2pdf...@googlegroups.com
Use really thin margins and then fake them using frames.

Scott Purcell

unread,
Apr 8, 2014, 2:03:52 PM4/8/14
to rst2pdf...@googlegroups.com
Perfect sense.  I don't think I'd fight the battle of trying to make rst2pdf work with a full-bleed image.  Rather, I'd create a separate document for the cover -- and then the book -- and then use pdftk or something like it to merge the PDFs together.

Scott Purcell

unread,
Apr 8, 2014, 2:06:03 PM4/8/14
to rst2pdf...@googlegroups.com
Or that :-)

If you're going to have the book printed though, better check with your printer on what's involved in full bleed images in the main body copy.  You may have to print on larger paper or trim to a smaller size to make it work.

Mike Driscoll

unread,
Apr 8, 2014, 3:55:51 PM4/8/14
to rst2pdf...@googlegroups.com
I am doing this currently, but when I do the merge, it deletes my table of contents that was created with the "contents" directive. If you or Roberto knows of a way to merge the PDFs without losing the TOC, I'm all ears.

I'll try the thin margins with frames thing if I can figure it out too.

- Mike

Mike Driscoll

unread,
Apr 10, 2014, 12:06:38 PM4/10/14
to rst2pdf...@googlegroups.com
Hi,

Just for the record, I was using pypdf for the merging. Last night, I tried using NitroPDF and ended up with the same issue (i.e. lost bookmarks). This morning I tried using PyPDF2 to do the merge and that appeared to retain the bookmarks, so I'm going to go with that solution right now. I also played around a bit with the margins + frames idea, but I can't get the cover image to fit correctly using that method.

Thanks to both of you for your suggestions. I appreciate it.

Mike
Reply all
Reply to author
Forward
0 new messages