PDF editing software?

"Please leave a message at the beep, we will get back to you when your support contract expires."

Moderators: phlip, Moderators General, Prelates

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

PDF editing software?

Postby MHD » Fri May 27, 2011 11:23 pm UTC

I have some old PDFs of books, and they are, because of their age (like, from 2003 or something), regrettably without the cunning index feature that most modern PDF books have.

Does there exist any software out there that can put indexes in such files? (preferably of the open source variety)
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"

User avatar
diabolo
Posts: 72
Joined: Fri Aug 08, 2008 4:17 pm UTC
Location: france

Re: PDF editing software?

Postby diabolo » Sun May 29, 2011 10:21 am UTC

Are we talking about the table of contents that appear in the bookmarks pane in pdf viewers?
You want to insert entries by hand not build a TOC automatically from the book?

Assuming both answers are yes, I suggest using latex to recompile a pdf.
Insert the original pdf using the 'pdfpages' package and add bookmarks using the 'bookmark' package.


edit: I tested on a simple case.
Started with this document:
original.pdf
Document with no bookmarks
(42.83 KiB) Downloaded 43 times


Then made this file to describe the bookmarks:
Spoiler:

Code: Select all

Lorem ipsum   2
   Dolor sit amet   2
   Consectetur adipiscing elit   2
      Suspendisse suscipit   2
      Eros id pellentesque   3
   Lacinia   3
Ipsum quam tristique urna   4
   Dignissim commodo   4
      Diam arcu a nunc   4
      Nulla pellentesque purus   4
   A odio ornare blandit   5
   Donec tincidunt   5
      Semper nunc   5
      Sed gravida nibh   6
      Feugiat bibendum   6
Phasellus vestibulum   6
   Condimentum massa   6
   Lobortis pellentesque   7
   Maecenas convallis metus   7
      A est mollis interdum   7
      Pulvinar lectus facilisis   7
      Cras hendrerit posuere magna   8

and used this (possibly ugly, I suck at perl) script:
Spoiler:

Code: Select all

#!/usr/bin/perl


if(!$ARGV[2]){
    print "usage: $0 input.pdf toc.txt outout.pdf\n";
    exit();
}

my $originalpdf = $ARGV[0];
my $tocfile = $ARGV[1];
my $outputpdf = $ARGV[2];

my $texfile = $outputpdf;
$texfile =~ s/(\.pdf)$/.tex/;

open TOC,"<",$tocfile or die("Could not open $tocfile");
open OUT,">",$texfile or die("Could not open $texfile");


# get original pdf size
my $id = `identify -format "%[pdf:HiResBoundingBox]" "${originalpdf}[0]"`;
$id =~ m/^([0-9.]+)x([0-9.]+).*$/;
my $papersize = ($1/72)."in,".($2/72)."in";


# latex preamble, begin doc
print OUT <<TEX
\\documentclass{minimal}
\\usepackage[a4paper]{geometry}
\\geometry{papersize={$papersize}}
\\usepackage{pdfpages}
\\usepackage{bookmark}
\\begin{document}
TEX
;

# bookmark commands
while(<TOC>){
    if($_=~m/^(\t*)([^\t]+)\t+([0-9+])$/){
        my $level = length($1);
        my $title = $2;
        my $page = $3;
        print OUT "\\bookmark[page=$page, level=$level]{$title}\n";
    }
}

# include original pdf, end doc
print OUT "\\includepdf[pages={1-last}]{$originalpdf}\n";
print OUT "\\end{document}\n";


# close, compile, clean
close TOC;
close OUT;
`rubber --pdf $texfile`;
`rubber --clean $texfile`;
unlink $texfile;

to produce this document:
recompiled.pdf
Document with added bookmarks
(54.33 KiB) Downloaded 37 times

User avatar
MHD
Posts: 630
Joined: Fri Mar 20, 2009 8:21 pm UTC
Location: Denmark

Re: PDF editing software?

Postby MHD » Sun May 29, 2011 2:48 pm UTC

That is exactly what I wanted, thank you!
EvanED wrote:be aware that when most people say "regular expression" they really mean "something that is almost, but not quite, entirely unlike a regular expression"


Return to “The Help Desk”

Who is online

Users browsing this forum: No registered users and 6 guests