6 use CGI::Carp qw(fatalsToBrowser);
\r
10 use Encode 'decode';
\r
17 # Copyright 2013 yukikaze, long.inus
\r
18 # Licensed under the Apache License, Version 2.0 (the "License");
\r
19 # you may not use this file except in compliance with the License.
\r
20 # You may obtain a copy of the License at
\r
22 # http://www.apache.org/licenses/LICENSE-2.0
\r
24 # Unless required by applicable law or agreed to in writing, software
\r
25 # distributed under the License is distributed on an "AS IS" BASIS,
\r
26 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
27 # See the License for the specific language governing permissions and
\r
28 # limitations under the License.
\r
32 my $mode = $cgi->param('mode');
\r
33 my $confpath = -e "libre10.conf" ? "libre10.conf" : "/etc/libre10.conf";
\r
34 my $confdata = YAML::XS::LoadFile($confpath);
\r
35 my $temppath = "/tmp/libre10/tmp" . generate_unique_key();
\r
36 my $dbh = DBI->connect( "dbi:SQLite:dbname=$confdata->{dburl}", "", "", { RaiseError => 1, AutoCommit => 1 } );
\r
37 my $pdflist = $dbh->selectall_hashref(
\r
38 "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
\r
42 mkdir '/tmp/libre10' unless ( -e '/tmp/libre10' );
\r
44 if ( $mode eq 'partpdf' ) {
\r
45 my $pdfid = $cgi->param('pdfid');
\r
46 my $pdftk = $cgi->param('pdftk');
\r
49 $pdftk =~ s/[^0-9\-]//;
\r
51 my $pdfpath = $pdflist->{$pdfid}->{path};
\r
52 exit unless ( -e $pdfpath );
\r
53 system "pdftk '$pdfpath' cat '$pdftk' output '$temppath.pdf'";
\r
54 my $length = -s "$temppath.pdf";
\r
55 print "Content-Type: application/pdf\n";
\r
56 print "Content-Length: $length\n";
\r
58 print read_file("$temppath.pdf");
\r
62 print $cgi->header( -charset => 'utf-8' );
\r
66 print qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03dd510&pdftk=765-765\n};
\r
67 my $ary_ref = $dbh->selectall_arrayref(
\r
68 "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
\r
72 print qq {<table>\n};
\r
74 print qq {<th>id</th>\n};
\r
75 print qq {<th>path</th>\n};
\r
76 print qq {<th>page</th>\n};
\r
77 print qq {<th>title</th>\n};
\r
78 print qq {<th>part</th>\n};
\r
79 print qq {<th>genre</th>\n};
\r
80 print qq {<th>start</th>\n};
\r
81 print qq {<th>end</th>\n};
\r
82 #print qq {<th>showpagediff</th>\n};
\r
83 #print qq {<th>indexpage</th>\n};
\r
85 foreach my $line ( @{$ary_ref} ) {
\r
87 print qq {<td><a href="./htmlserver.pl?pdfpath=$line->{id}&pagenum=1">$line->{id}</a></td>\n};
\r
88 print qq {<td>$line->{path}</td>\n};
\r
89 print qq {<td>$line->{page}</td>\n};
\r
90 print qq {<td>$line->{title}</td>\n};
\r
91 print qq {<td>$line->{part}</td>\n};
\r
92 print qq {<td>$line->{genre}</td>\n};
\r
93 print qq {<td>$line->{startpage}</td>\n};
\r
94 print qq {<td>$line->{endpage}</td>\n};
\r
95 #print qq {<td>$line->{showpagediff}</td>\n};
\r
96 #print qq {<td>$line->{indexpage}</td>\n};
\r
99 print qq {</table>\n};
\r
102 sub generate_unique_key {
\r
104 my @str = ( 0 .. 9, 'A' .. 'Z', 'a' .. 'z' );
\r
106 foreach ( 1 .. 8 ) {
\r
107 $ukey .= $str[ int( rand(@str) ) ];
\r