2

I have been writing shell scripts for converting the AMD64 Handbook of Gentoo Linux to PDF and this is my current shell script:

function ghand {
  # Input 1 is the architecture
  # Input 2 is the Page name.
  mkdir -p ~/Textbooks/Gentoo/$1/$2/..
  cd ~/Textbooks/Gentoo/$1/$2/..
  wkhtmltopdf https://wiki.gentoo.org/wiki/Handbook:"$1"/"$2" "${2##*/}".pdf
}

function ghandall {
  mkdir -p ~/Textbooks/Gentoo/$1 && cd ~/Textbooks/Gentoo/$1
  wkhtmltopdf https://wiki.gentoo.org/wiki/Handbook:"$1" "$1".pdf

  # Installation
  S=Installation
  L=('About' 'Base' 'Bootloader' 'Disks' 'Finalizing' 'Kernel' 'Media' 'Networking' 'Stage' 'System' 'Tools')
  for i in "${L[@]}"
  do
    ghand $1 "$S"/"$i"
  done
  unset L
  unset S

  # Working with Gentoo
  S=Working
  L=('EnvVar' 'Features' 'Initscripts' 'Portage' 'USE')
  for i in "${L[@]}"
  do
    ghand $1 "$S"/"$i"
  done
  unset L
  unset S

  # Working with Portage
  S=Portage
  L=('Advanced' 'Branches' 'CustomTree' 'Files' 'Tools' 'Variables')
  for i in "${L[@]}"
  do
    ghand $1 "$S"/"$i"
  done
  unset L
  unset S

  # Networking
  S=Networking
  L=('Advanced' 'Dynamic' 'Extending' 'Introduction' 'Modular' 'Wireless')
  for i in "${L[@]}"
  do
    ghand $1 "$S"/"$i"
  done
  unset L
  unset S
}

function unit {
  pushd ~/Textbooks/Gentoo/"$1"
  pdfunite "$1".pdf */*.pdf "Handbook:"$1"".pdf
  popd
}

running ghandall AMD64 && unit AMD64 gives the complete AMD64 handbook in PDF format, although the problem is that the resulting PDF doesn't have any of the formatting provided by CSS styles in the Handbook's original HTML format. For example, this:

original formatting @ Gentoo Wiki

gets rendered as:

final rendering in PDF

in the final PDF. Does anyone know how I might overcome this problem? If you recommend I use a different program to wkhtmltopdf to convert these webpages to PDF, please ensure it is free, invokable from the command-line and available on Sabayon Linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.