Package: pod2pdf
Version: 0.42-2
Severity: wishlist
Tags: patch
Dear Maintainer,
I wrote a patch to add an option for adding PDF Outlines. This feature
is controlled by a command switch (--outlines). Hope it will be useful.
(Note: The patch is written against the upstream source.)
Guo Yixuan
-- System Information:
Debian Release: wheezy/sid
APT prefers testing
APT policy: (500, 'testing')
Architecture: i386 (i686)
Kernel: Linux 3.1.0-1-686-pae (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash
Versions of packages pod2pdf depends on:
ii libgetopt-argvfile-perl 1.11-1
ii libpdf-api2-perl 2.019-1
ii perl 5.14.2-5
ii perl-modules 5.14.2-5
Versions of packages pod2pdf recommends:
ii libfile-type-perl 0.22-1.1
ii libimage-size-perl 3.230-1
pod2pdf suggests no packages.
-- no debconf information
diff -ur pod2pdf-0.42/bin/pod2pdf pod2pdf-changed/bin/pod2pdf
--- pod2pdf-0.42/bin/pod2pdf 2007-09-14 01:12:02.000000000 +0800
+++ pod2pdf-changed/bin/pod2pdf 2011-12-07 14:12:15.000000000 +0800
@@ -66,6 +66,7 @@
'icon-scale' => '=s',
'timestamp' => '!',
'output-file' => '=s',
+ 'outlines' => '!',
);
my %config;
@@ -203,6 +204,10 @@
Sets an optional footer text string that will be included in the bottom left corner
of each page.
+=item C<--outlines>
+
+Adds outlines (bookmarks) to pdf according to headings (=head1, =head2, ...).
+
=item C<--version>
Prints version number and exits.
diff -ur pod2pdf-0.42/lib/App/pod2pdf.pm pod2pdf-changed/lib/App/pod2pdf.pm
--- pod2pdf-0.42/lib/App/pod2pdf.pm 2007-10-26 16:08:54.000000000 +0800
+++ pod2pdf-changed/lib/App/pod2pdf.pm 2011-12-07 14:17:24.000000000 +0800
@@ -83,6 +83,7 @@
} else {
$self->{y_position} -= ($heading_space - $default_space);
}
+ $self->print_outline($expansion, $command, $self->{page_number}, $self->{x_position}, $self->{y_position} + $heading_space) if $self->{outlines};
$self->print_text_with_style($expansion,$command);
$self->spacer;
$self->indent(48);
@@ -492,6 +493,9 @@
$self->{pdf} = PDF::API2->new;
$self->{pdf}->info('Producer'=>"$class version $version");
$self->{pdf}->mediabox($self->{page_width},$self->{page_height});
+
+ # push the root Outlines object in to outline_stack
+ push @{$self->{outline_stack}}, $self->{pdf}->outlines();
if ($self->{icon} && $self->images) {
if (-e $self->{icon}) {
@@ -925,6 +929,60 @@
#-----------------------------------------------------------------------
+
+# add outlines to the pdf file
+# using $self->{outline_stack} for recursive structure of PDF Outlines
+# print_outline($text, $style, $page, $x, $y)
+
+#-----------------------------------------------------------------------
+
+sub print_outline {
+ my $self = shift;
+ my $text = shift;
+ $text =~ s/\s*$//; # remove trailing newlines and spaces
+
+ my $style = shift;
+
+ my $page = shift; #$self->{page_number};
+ # actually $page is not needed (openpage(0) is current page)
+ my $pdfpage = $self->{pdf}->openpage($page);
+
+ my $x = shift;
+ my $y = shift;
+
+ my %level = (
+ 'head1' => 1,
+ 'head2' => 2,
+ 'head3' => 3,
+ 'head4' => 4,
+ );
+ my $level = $level{$style};
+ my $up_level = $level - 1;
+ my $cur_level = scalar @{$self->{outline_stack}} - 1;
+
+ # finding the right place to insert new outline
+ while ($cur_level < $up_level) {
+ my $tail = $self->{outline_stack}[-1];
+ push @{$self->{outline_stack}}, $tail->outline();
+ $cur_level ++;
+ }
+ while ($cur_level > $up_level) {
+ pop @{$self->{outline_stack}};
+ $cur_level --;
+ }
+ my $tail = $self->{outline_stack}[-1];
+
+ # create a new sub-outline, setting title and dest
+ my $outline = $tail->outline();
+ $outline->title($text);
+ # $outline->dest($pdfpage);
+ # $outline->dest($pdfpage, "-xyz" => [$self->{x_position}, $self->{y_position}, 0]);
+ $outline->dest($pdfpage, "-xyz" => [$x, $y, 0]);
+
+ push @{$self->{outline_stack}}, $outline;
+}
+
+#-----------------------------------------------------------------------
#-----------------------------------------------------------------------
# PDF file output