emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] Using org to create a TOC for a compilation of separate PDF docu


From: AW
Subject: Re: [O] Using org to create a TOC for a compilation of separate PDF documents
Date: Fri, 24 May 2013 11:09:11 +0200
User-agent: KMail/4.10.3 (Linux/3.8.9-4-desktop; KDE/4.10.3; x86_64; ; )

Am Donnerstag, 23. Mai 2013, 23:48:03 schrieb Marcin Borkowski:
> Dnia 2013-05-23, o godz. 15:21:56
> 
> John Hendy <address@hidden> napisaƂ(a):
> > I have a use case and am not sure if Org would help or not. I've
> > downloaded a bunch of technical data sheets on various materials from
> > a vendor. I'd like to create a "booklet" of them with a cover page
> > table of contents.
> > 
> > I can create the booklet very easily with Stapler (or similar), but am
> > not sure on the best way to generate a clickable linked PDF of the
> > individual materials contained in the compiled document.[1] What I'm
> > not sure on is how to create a table of contents.
> > 
> > Ideally, I could do something like generate a page count of each
> > document and then use this to create the page numbers I'd use to
> > create links to, which I thought I could do with Org. Even better
> > would be to have [back to top] links as well, since this will end up
> > being a multi-hundred page booklet (~100 documents of 2-4 pages each).
> > 
> > Any thoughts on this?
> > 
> > Is it easier to just generate a list of files and use Org to "include"
> > them somehow via LaTeX instead of using Stapler to combine them?
> 
> I'd just use LaTeX's pdfpages package, possibly with hyperref.  (If you
> encounter any problems, email me - I've done similar things before, so
> I guess I could help you.)
> 

You don't have to do that manually. Some time ago members of the German TEX-D-
List put together a bash script, which takes all the PDFs recursivly and 
creates a *.tex file:

#+begin_src bash

#!/bin/bash
#
# pdfdir OUTPUT_FILE
#
# produces one big PDF file of all PDF files in .
#
if [ $# -ne 1 ] || [ -z "$1" ]; then
  echo "Syntax: pdfdir OUTPUT_FILE"
  exit 1
fi
FILE="$(echo "$1"|sed -e 's/\.\(pdf\|tex\)$//')"
for F in "$FILE" "$FILE.tex" "$FILE.pdf" "$FILE.aux" "$FILE.log" ; do
  if [ -e "$F" ]; then
    echo "$F already exists."
    exit 2
  fi
done
cat >"$FILE.tex" <<EOF
\documentclass{article}%
\usepackage{pdfpages}%
\usepackage{grffile}%
\listfiles%
\begin{document}%
%\tableofcontents%
EOF
# Helperfunction
exist_pdf_files () {
  [ $(find -L "$1" -name \*.pdf -o -name \*.PDF -type f 2>/dev/null|wc -l) -eq 
0 ] && return 1
  return 0
}
list_directories () {
  find -L "$1" -maxdepth 1 -mindepth 1 -type d 2>/dev/null | sort
}
list_pdf_files () {
  # " around filenames:
  find -L "$1" -maxdepth 1 -mindepth 1 -name \*.pdf -o -name \*.PDF -type f 
2>/dev/null | sort | \
    sed -e 's/^/\\includepdf[pages=-]{"/; s/$/"}%/'
  # without " around filenames:
 # find -L "$1" -maxdepth 1 -mindepth 1 -name \*.pdf -o -name \*.PDF -type f 
2>/dev/null | sort | \
  #  sed -e 's/^/\\includepdf[pages=-]{/; s/$/}%/'
}
tex_headline () {
    echo "$1" | sed -e 's/_/\\_/g'
}
# folder level were we are (level 0):
list_pdf_files . >>"$FILE.tex"
# level 1:
list_directories . | while read -r DIR1; do
  # Are there PDF files a level down?
  exist_pdf_files "$DIR1" || continue
  # Yes...
  tex_headline "\section{${DIR1##*/}}%"
  # ... those are ...:
  list_pdf_files "$DIR1"
  # Level 2:
  list_directories "$DIR1" | while read -r DIR2; do
    exist_pdf_files "$DIR2" || continue
    tex_headline "\subsection{${DIR2##*/}}%"
    list_pdf_files "$DIR2"
    # Level 3:
    list_directories "$DIR2" | while read -r DIR3; do
      exist_pdf_files "$DIR3" || continue
      tex_headline "\subsubsection{${DIR3##*/}}%"
      list_pdf_files "$DIR3"
      # Level 4:
      list_directories "$DIR3" | while read -r DIR4; do
        exist_pdf_files "$DIR4" || continue
        tex_headline "\paragraph{${DIR4##*/}}%"
        list_pdf_files "$DIR4"
        # Level 5:
        list_directories "$DIR4" | while read -r DIR5; do
          exist_pdf_files "$DIR5" || continue
          tex_headline "\subparagraph{${DIR5##*/}}%"
          list_pdf_files "$DIR5"
        done
      done
    done
  done
done >>"$FILE.tex"
echo "\end{document}%" >>"$FILE.tex"
echo "Compile source now? [J/n]"
read -r ANSWER
case "$ANSWER" in
[JjYy]) ;;
*) exit 0 ;;
esac
pdflatex "$FILE"
[ $? -eq 0 ] && rm -f "$FILE.aux" "$FILE.log" "$FILE.tex"



#+end_src

I found that very helpfull, but I did not use it recently.

Regards,

Alexander

> > Thanks for any suggestions!
> > John
> 
> Best,

Attachment: book-from-PDF.sh
Description: application/shellscript


reply via email to

[Prev in Thread] Current Thread [Next in Thread]