PDFs aren't rendered with CSS

1,211 views
Skip to first unread message

Colin Fleming

unread,
Nov 13, 2008, 5:49:47 PM11/13/08
to xhtm...@googlegroups.com
Hi all,

I'm trying to use XHTML2PDF to render PDFs of the online book Real World Haskell (book.realworldhaskell.org). However the resulting PDFs don't have any styling, it's obviously not picking up the style sheet. I fixed up the HTML a little so it works with no warnings:

~/book.realworldhaskell.org/read> xhtml2pdf  -w getting-started.html
Converting getting-started.html to /Users/colin/book.realworldhaskell.org/read/getting-started.pdf...
~/book.realworldhaskell.org/read>

But the doc has no styling. Using css-dump shows the default styling:

~/book.realworldhaskell.org/read> xhtml2pdf  --css-dump getting-started.html

html {
   font-family: Helvetica;
   font-size: 10px;
   font-weight: normal;
   color: #000000;
   background-color: transparent;
   margin: 0;
   padding: 0;
   line-height: 150%;
   border: 1px none;
   display: inline;
   width: auto;
   height: auto;
   white-space: normal;    
}
<etc etc>

And using debug doesn't show much:

~/book.realworldhaskell.org/read> xhtml2pdf  -d getting-started.html
Converting getting-started.html to /Users/colin/book.realworldhaskell.org/read/getting-started.pdf...
DEBUG [ho.pisa] /opt/local/lib/python2.5/site-packages/pisa-3.0.27-py2.5.egg/sx/pisa3/pisa_document.py line 92: pisaDocument options:
  src = <open file '/Users/colin/book.realworldhaskell.org/read/getting-started.html', mode 'rb' at 0x8c260>
  dest = <open file '/Users/colin/book.realworldhaskell.org/read/getting-started.pdf', mode 'wb' at 0x788d8>
  path = '/Users/colin/book.realworldhaskell.org/read/getting-started.html'
  link_callback = None
  xhtml = False

Finally, specifying the CSS path results in an error:

~/book.realworldhaskell.org/read> xhtml2pdf  -c styles.css getting-started.html
Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/2.5/bin/xhtml2pdf", line 8, in <module>
    load_entry_point('pisa==3.0.27', 'console_scripts', 'xhtml2pdf')()
  File "/opt/local/lib/python2.5/site-packages/pisa-3.0.27-py2.5.egg/sx/pisa3/pisa.py", line 269, in command
    css = file(a, "r").read()
IOError: [Errno 2] No such file or directory: ''

Does anyone have any idea what might be going wrong?

Thanks for any help,
Colin

Dirk Holtwick

unread,
Nov 14, 2008, 2:27:50 AM11/14/08
to xhtm...@googlegroups.com
Did you download all styles and images too? Did you have a look in your
browser with "Print Preview" because that is how the PDF is like to
render? Simply try the following, I think it will lead to a better result ;)

$ xhtml2pdf -sw http://book.realworldhaskell.org/read/getting-started.html

Dirk

Colin Fleming schrieb:
> Hi all,
>
> I'm trying to use XHTML2PDF to render PDFs of the online book Real World
> Haskell (book.realworldhaskell.org <http://book.realworldhaskell.org>).
> However the resulting PDFs don't have any styling, it's obviously not
> picking up the style sheet. I fixed up the HTML a little so it works
> with no warnings:
>
> ~/book.realworldhaskell.org/read
> <http://book.realworldhaskell.org/read>> xhtml2pdf -w getting-started.html
> Converting getting-started.html to
> /Users/colin/book.realworldhaskell.org/read/getting-started.pdf.
> <http://book.realworldhaskell.org/read/getting-started.pdf.>..
> ~/book.realworldhaskell.org/read <http://book.realworldhaskell.org/read>>
>
> But the doc has no styling. Using css-dump shows the default styling:
>
> ~/book.realworldhaskell.org/read
> <http://book.realworldhaskell.org/read>> xhtml2pdf --css-dump
> getting-started.html
>
> html {
> font-family: Helvetica;
> font-size: 10px;
> font-weight: normal;
> color: #000000;
> background-color: transparent;
> margin: 0;
> padding: 0;
> line-height: 150%;
> border: 1px none;
> display: inline;
> width: auto;
> height: auto;
> white-space: normal;
> }
> <etc etc>
>
> And using debug doesn't show much:
>
> ~/book.realworldhaskell.org/read
> <http://book.realworldhaskell.org/read>> xhtml2pdf -d getting-started.html
> Converting getting-started.html to
> /Users/colin/book.realworldhaskell.org/read/getting-started.pdf.
> <http://book.realworldhaskell.org/read/getting-started.pdf.>..
> DEBUG [ho.pisa]
> /opt/local/lib/python2.5/site-packages/pisa-3.0.27-py2.5.egg/sx/pisa3/pisa_document.py
> line 92: pisaDocument options:
> src = <open file
> '/Users/colin/book.realworldhaskell.org/read/getting-started.html
> <http://book.realworldhaskell.org/read/getting-started.html>', mode 'rb'
> at 0x8c260>
> dest = <open file
> '/Users/colin/book.realworldhaskell.org/read/getting-started.pdf
> <http://book.realworldhaskell.org/read/getting-started.pdf>', mode 'wb'
> at 0x788d8>
> path =
> '/Users/colin/book.realworldhaskell.org/read/getting-started.html
> <http://book.realworldhaskell.org/read/getting-started.html>'
> link_callback = None
> xhtml = False
>
> Finally, specifying the CSS path results in an error:
>
> ~/book.realworldhaskell.org/read
> <http://book.realworldhaskell.org/read>> xhtml2pdf -c styles.css

Colin Fleming

unread,
Nov 14, 2008, 3:01:31 PM11/14/08
to xhtm...@googlegroups.com
Yep, I've downloaded all the images and styles, it renders correctly in the browser. I don't want to use the public version, I've edited the css in the copy I've downloaded slightly because I'm creating PDFs for an e-reader and the public version has enormous margins (which is why I downloaded it).

Cheers,
Colin

2008/11/14 Dirk Holtwick <dirk.h...@gmail.com>

Dirk Holtwick

unread,
Nov 17, 2008, 12:31:50 PM11/17/08
to xhtm...@googlegroups.com
Colin Fleming schrieb:

> Yep, I've downloaded all the images and styles, it renders correctly in
> the browser. I don't want to use the public version, I've edited the css
> in the copy I've downloaded slightly because I'm creating PDFs for an
> e-reader and the public version has enormous margins (which is why I
> downloaded it).

Did you try to open the local copy of you HTML file in your browser and
has it loaded all styles and images (even without ? Sorry for all my
questions, but I want to figure out where the problem is and if it is
inside of xhtml2pdf.

Dirk

Colin Fleming

unread,
Nov 18, 2008, 6:47:18 AM11/18/08
to xhtm...@googlegroups.com
Hi Dirk,

Yep, I did, it all rendered correctly. However I didn't look into it too much, I ended up using Prince XML (which is free for my purposes).

Cheers,
Colin

2008/11/17 Dirk Holtwick <dirk.h...@gmail.com>

Dirk Holtwick

unread,
Nov 18, 2008, 6:59:25 AM11/18/08
to xhtm...@googlegroups.com
Colin Fleming schrieb:

> Yep, I did, it all rendered correctly. However I didn't look into it too
> much, I ended up using Prince XML (which is free for my purposes).

Since when it is free?

Dirk

Colin Fleming

unread,
Nov 18, 2008, 7:22:38 AM11/18/08
to xhtm...@googlegroups.com
I'm not sure - I did look at it a while ago and I'm pretty sure it wasn't then. It's now free for personal use in a single computer. It puts a small logo on the first page, but I can live with that.

Cheers,
Colin

2008/11/18 Dirk Holtwick <dirk.h...@gmail.com>

Dirk Holtwick

unread,
Nov 18, 2008, 7:40:32 AM11/18/08
to xhtm...@googlegroups.com
> I'm not sure - I did look at it a while ago and I'm pretty sure it
> wasn't then. It's now free for personal use in a single computer. It
> puts a small logo on the first page, but I can live with that.

Thanks for the informations, Colin.

Cheers
Dirk

Cavan

unread,
Nov 21, 2008, 3:47:25 AM11/21/08
to Pisa XHTML2PDF Support
If your pulling the CSS from an external stylesheet, try setting the
media to all.

For example:
<link href="test.css" media="all" rel="stylesheet" type="text/css>

It should also work to set it to print, however then you cant get a
rough look at it in the browser.

Dirk Holtwick

unread,
Nov 21, 2008, 4:06:30 AM11/21/08
to xhtm...@googlegroups.com
Hi,

this is a bug. I fixed it for the next release. Thanks for your patience.

Dirk

Cavan schrieb:
Reply all
Reply to author
Forward
0 new messages