mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / PDF_bookmarks_with_Ghostscript.mdwn
index af22b97b3a0414ff25fd76c02442032122ea2484..8ba2903d43a0102c56b2f531bad7a639e406e8f7 100644 (file)
@@ -1,7 +1,7 @@
 I was recently trying to add bookmarks to a [[PDF]] I'd generated with
-[pdftk][].  It turns out to be fairly simple to add bookmarks to a PDF
+[[pdftk]].  It turns out to be fairly simple to add bookmarks to a PDF
 using [Ghostscript][], following [maggoteer's post][post] to the
-Ubunto forums.  The syntax is:
+Ubuntu forums.  The syntax is:
 
     $ gs -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -sOutputFile=out.pdf in-*.pdf pdfmarks
 
@@ -14,9 +14,47 @@ and `pdfmarks` is a text file with contents like:
 
 Nice and easy.
 
-[pdftk]: http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
+For nested levels, use the `/Count` attribute.  For example:
+
+    [/Count 3 /Title (Chapter 1) /Page 1 /OUT pdfmark
+    [/Count -2 /Title (Section 1.1) /Page 2 /OUT pdfmark
+    [/Title (Section 1.1.1) /Page 3 /OUT pdfmark
+    [/Title (Section 1.1.2) /Page 4 /OUT pdfmark
+    [/Count -1 /Title (Section 1.2) /Page 5 /OUT pdfmark
+    [/Title (Section 1.2.1) /Page 6 /OUT pdfmark
+    [/Title (Section 1.3) /Page 7 /OUT pdfmark
+
+The argument to `/Count` gives the number of immediately subordinate
+bookmarks.  The sign of the argument sets the default display
+(negative for closed, positive for open).
+
+You can also setup the document info dictionary with something like:
+
+    [ /Title (My Test Document)
+      /Author (John Doe)
+      /Subject (pdfmark 3.0)
+      /Keywords (pdfmark, example, test)
+      /DOCINFO pdfmark
+
+If you want more detail, take a look at [Adobe's pdfmark
+reference][reference].
+
+I've bundled the whole pdfmarks-generation bit into a script,
+[[pdf-merge.py]], which generates the pdfmark file and runs
+Ghostscript automatically.  Think of it as a bookmark-preserving
+version of pdftk's `cat`.  The script uses [[pdftk]] internally to
+extract bookmark information from the source PDFs.
+
+The script also adds a bit of PostScript to ignore any bookmarks in
+the source PDFs during the Ghostscript run.  The only bookmarks in the
+output will be the ones you specify explicitly in the pdfmarks file.
+If for some reason the automatically generated pdfmarks are not quite
+what you want, the script can pause (via `--ask`) to allow you to
+tweak the pdfmarks manually before running Ghostscript.
+
 [Ghostscript]: http://ghostscript.com/
 [post]: http://ubuntuforums.org/showthread.php?t=1545064
+[reference]: http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/pdfmark_reference.pdf
 
 [[!tag tags/tools]]
 [[!tag tags/linux]]