I would like to convert an online book (linked html files) into a pdf file.

I tried the two-step way in http://kmkeen.com/mirror/2009-02-05-14-00-00.html

  1. First, download the html files by

    wget -nd -mk http://www.unknownroad.com/rtfm/gdbtut/

    But it has downloaded a lot of nonrelated files. So I have to remove the unrelated files.

  2. Then, I try to convert the downloaded html book into a pdf file:

    htmldoc --webpage -f gdb.pdf html/index.html html/*.html

    but the order of pages in the pdf file isn't correct.

I wonder what good way to download and convert an online book (linked html files) into a pdf file?

My OS is Ubuntu 12.04.

1 Answer 1


As mentioned in the instructions you linked:

The default glob expansion puts the pages in alphabetical order.

The index page links to nine different documents, whose names aren't in alphabetical order. When you say htmldoc ... *.html, the tools sees them in that order and puts the pages into the document alphabetically. You need to list the files on the command line in the order you want htmldoc to process them.

In this specific case you can produce an ordered list of filenames as they're linked in the index with:

awk '/http:|\.\./ {next}; /<a href.*\.html/ { gsub(/.*href="/, "") ; gsub(".html.*", ".html") ; print }' index.html | uniq


htmldoc --webpage -f gdb.pdf index.html $(awk '/http:|\.\./ {next}; /<a href.*\.html/ { gsub(/.*href="/, "") ; gsub(".html.*", ".html") ; print }' index.html | uniq)

will have the effect you want.

  • Thanks. about 1, wget -nd -mk http://www.unknownroad.com/rtfm/gdbtut/ also downloads files under http://www.unknownroad.com. How could I download the files under http://www.unknownroad.com/rtfm/gdbtut/ only?
    – Tim
    Commented Aug 20, 2014 at 13:08
  • See wget's --domains and --no-parent options. Commented Aug 20, 2014 at 21:46
  • 1
    Thanks, Michael. Can htmldoc create multilevel bookmarks in the resulting pdf file? unix.stackexchange.com/questions/153433/…
    – Tim
    Commented Sep 3, 2014 at 1:19

You must log in to answer this question.

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