-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake_endpieces.pl
executable file
·144 lines (98 loc) · 2.92 KB
/
make_endpieces.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env perl
#===============================================================================
#
#===============================================================================
use strict;
use warnings;
use PDF::API2;
use lib ( qw(inc) );
use pod2pdf;
use POSIX qw(locale_h);
print "Making FrontPage.pdf...";
# Create a blank PDF file
my $pdf = PDF::API2->new();
# Add a blank page
my $page = $pdf->page();
# Set the page size
$page->mediabox('A4');
# Add a built-in font to the PDF
my $font = $pdf->corefont('Helvetica-Bold');
# Add some text to the page
my $text = $page->text();
$text->font($font, 64);
$text->translate(70, 700);
$text->text('The PDL Book');
$text->font($font, 24);
$text->translate(70, 500);
$text->text('June 2015');
$text->font($font, 24);
$text->translate(70, 90);
$text->text('for PDL 2.011');
# Save the PDF
$pdf->saveas('FrontPage.pdf');
print "done\n";
##############################
# TOC
#############################
open (FIN, "<toc.txt") or die "cannot open toc.txt";
if (-e "toc.pod") {unlink "toc.pod"; print "Deleted old toc.pod\n"};
open (FOUT, ">toc.pod") or die "cannot open toc.pod";
my $h1 = 0;
my $h2 = 0;
my $h3 = 0;
my $h4 = 0;
my $last_level = 1;
print FOUT "=head1 Table of Contents\n\n";
while (<FIN>) {
next if (! /TOC/);
chomp;
my @p = split;
shift @p;
shift @p;
my $page = shift @p;
my $head = shift @p;
my $title = join " ", @p;
my $curr_level = substr $head, -1, 1;
if ($curr_level == 1) {$h1++;}
if ($curr_level == 2) {$h2++;}
if ($curr_level == 3) {$h3++;}
if ($curr_level == 4) {$h4++;}
if ($curr_level < $last_level) {
if ($curr_level == 1) {$h2=0;$h3=0;$h4=0;}
if ($curr_level == 2) {$h3=0;$h4=0;}
if ($curr_level == 3) {$h4=0;}
}
print FOUT " ";
if ($curr_level == 1) { print FOUT "\n $h1. "; }
if ($curr_level == 2) { print FOUT "$h1.$h2 "; }
if ($curr_level == 3) { print FOUT "$h1.$h2.$h3 "; }
if ($curr_level == 4) { print FOUT "$h1.$h2.$h3 "; }
print FOUT "$title - p.$page\n";;
$last_level = $curr_level;
}
close(FOUT);
my %config = (
page_number => 0,
icon_scale => 0.25,
title => "Table of Contents",
icon => "PDL/Book/logo2.png",
);
&make_pdf_wrapper("toc.pod","toc.pdf");
sub make_pdf_wrapper {
my $file = shift;
my $outpdf = shift;
print "Making $outpdf from $file...";
# uses %config from global. yes, I'm lazy.
open (BLARG,">$outpdf") or die("Cannot open output file $outpdf: $!\n");
#--Tell the OS we are going to create binary data--------------------------
setlocale(LC_ALL,'C');
binmode *BLARG;
#--Parse our Pod-----------------------------------------------------------
my $parser = App::pod2pdf->new(%config);
$parser->parse_from_file($file);
#$parser->output;
print BLARG $parser->{pdf}->stringify;
close(BLARG);
print "done\n";
return ($parser->{page_number});
}