2

Is there a way I can convert large html file (produced with sphinx by the way) to pdf with color, table of contents (toc) and unicode support?

There's htmldoc -- but it neither support color, nor unicode.

There's rst2pdf sphinx plugin -- but currently it breaks math rendering, and also can't word-warp code lines.

There's a way to export to xetex in sphinx -- but it can't word-wrap code-blocks, and also don't support svg images.

Edit:

I tried to use pandoc:

pandoc index.html --mathjax --toc -o index.pdf

it gives:

pandoc: Error producing PDF from TeX source.
! LaTeX Error: Command \guillemotright unavailable in encoding OT1.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.55   2012-Sep-11} »

I'm stucked...

2
  • Edit your LaTeX code, and add this line at the beginning: \usepackage[utf8]{inputenc}
    – terdon
    Sep 11, 2012 at 14:08
  • But it won't wrap code. In latex you can only wrap code it you're using listings. But I have code colored by pygments -- and in listings I can't get it parse that coloring... So You see -- I worked in this way -- latex doesn't work really.
    – Adobe
    Sep 11, 2012 at 14:10

3 Answers 3

1

Have you tried wkhtmltopdf? It's based on WebKit, and has CSS support, of course with colors.

It doesn't have TOC support, err, i guess it does.

It's basically rendering to PDF.

4
  • Versions 0.10.0 and above does have a toc support: wkhtmltopdf toc my.html my.pdf. I see that the firefox extension I tried uses exactly this lib.
    – Adobe
    Sep 11, 2012 at 15:10
  • @Adobe cool, I may have used an older version that didn't have TOC, i hope this works for you. Sep 11, 2012 at 15:15
  • Well currently I'm trying to figure out how to set width of the content. Despite toc has correct width my body is not. Perhaps it is set somewhere in my css...
    – Adobe
    Sep 11, 2012 at 15:49
  • 1
    Yep, solved it with body { width: 150%; } addition to css. The command I use: ./wkhtmltopdf-0.10.0-amd64 --enable-javascript --javascript-delay 5000 --no-stop-slow-scripts --no-background toc index.html 1.pdf
    – Adobe
    Sep 11, 2012 at 16:12
1

If you are on linux or Mac, you can try html2pdf or html2ps foo.html; ps2pdf foo.ps. Neither of these methods is perfect but they might work.

You can also try opening the file in an office suite and export to pdf. I know that both word and libreoffice support this. This is the only option I know of if you are using windows.

The best way would be to export the file as TeX or LaTeX and compile the pdf, you can edit the LaTeX code to fix any wrapping issues. You can also easily convert your images to png using convert from ImageMagick:

$ mogrify -format png *.svg
5
  • LibreOffice deforms images and doesn't render math. LaTeX doesn't support UTF and can't wrap code (as I point in the question).
    – Adobe
    Sep 11, 2012 at 13:20
  • @Adobe, LaTeX does support utf8. I don't know what environment LaTeX uses for your code blocks but you should be able to mke them wrap with a minimum of editing. You haven't said what OS you are using, on Linux at least, you can "print to pdf" instead of a printer so you could do it directly from your browser.
    – terdon
    Sep 11, 2012 at 13:53
  • But is there a way I can get a pdf with toc -- when printing to pdf? I'm using Kubuntu linux, but I can go for any OS if -- there's a solution. Sphinx uses Verbatim LaTeX environment in code blocks and these are absolutely impossible to word-wrap.
    – Adobe
    Sep 11, 2012 at 13:59
  • It depends on how your toc is set up. Does latex give you a toc? As for code blocks, you can replace verbatim with a simple float and change the font inside the float. Getting beyond the scope of your question though. Try printing the html doc and choosing "print to pdf" as the printer.
    – terdon
    Sep 11, 2012 at 14:05
  • My index.html doesn't have a toc (it can't have one -- because there's no pages). I want to get a book with toc out of single large html file. Simpe print to pdf won't produce no toc.
    – Adobe
    Sep 11, 2012 at 14:07
0

Print pages to pdf firefox addon does make a toc.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .