use warnings;
use CGI;
use File::Basename;
+
#
# Libre10
# Copyright 2013 yukikaze
$width = $cgi->param("width");
$bpage = $pagenum - 1;
$npage = $pagenum + 1;
-$blink = "htmlserver.pl?pdfpath=$pdfpath&mode=$mode&width=$width&height=$height";
+$blink =
+ "htmlserver.pl?pdfpath=$pdfpath&mode=$mode&width=$width&height=$height";
$nlink = $blink . "&pagenum=" . $npage;
$blink = $blink . "&pagenum=" . $bpage;
-$jpeglink = "jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$pagenum&mode=$mode&height=$height&width=$width";
+$jpeglink =
+"jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$pagenum&mode=$mode&height=$height&width=$width";
#print "Content-type:text/html\n\n";
print $cgi->header( -charset => 'utf-8' );
print "<html lang='ja'>\n<head>\n <meta charset='utf-8'>";
print "<meta name='viewport' content='width=device-width, initial-scale=1'>\n";
-$linkfrm = qq{<hr><div data-role="header" align='center'><a href='$blink' data-prefetch>前へ</a>};
-$linkfrm .= qq{page $pagenum \n<a href='$nlink' data-prefetch>次へ</a></div><hr>\n};
+$linkfrm =
+qq{<hr><div data-role="header" align='center'><a href='$blink' data-prefetch>前へ</a>};
+$linkfrm .=
+qq{page $pagenum \n<a href='$nlink' data-prefetch>次へ</a></div><hr>\n};
if ( $mode eq "mobile" ) {
- print "<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css\" />\n";
- print "<script src=\"http://code.jquery.com/jquery-1.9.1.min.js\"></script>\n";
- print "<script src=\"http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js\"></script>\n";
- $linkfrm = qq{<div data-role=\"header\" align='center'><a href='$blink'data-icon='arrow-l' data-prefetch>前へ</a> };
+ print
+"<link rel=\"stylesheet\" href=\"http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css\" />\n";
+ print
+ "<script src=\"http://code.jquery.com/jquery-1.9.1.min.js\"></script>\n";
+ print
+"<script src=\"http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js\"></script>\n";
+ $linkfrm =
+qq{<div data-role=\"header\" align='center'><a href='$blink'data-icon='arrow-l' data-prefetch>前へ</a> };
$linkfrm .= qq{<h3>page $pagenum</h3>};
- $linkfrm .= qq{ \n<a href='$nlink' data-icon='arrow-r' data-prefetch>次へ</a></div>\n};
+ $linkfrm .=
+qq{ \n<a href='$nlink' data-icon='arrow-r' data-prefetch>次へ</a></div>\n};
$swipescript = "<script type='text/javascript'>
\$('#page').live('pagecreate',function(){
\$('#page').live('swipeleft',image_back);
#$linkfrm .="page " . $pagenum . "</h3>" ;
#$linkfrm .=" \n<a href='" . $nlink . "' data-prefetch>次へ</a></div>\n";
print $linkfrm;
-print "<div data-role=\"content\" id='image'><img src='$jpeglink' width='100%'/>";
+print
+ "<div data-role=\"content\" id='image'><img src='$jpeglink' width='100%'/>";
print "</div>";
print $linkfrm;
-print "<div align=center data-role='footer'>Libre10 git '13Q2<BR>Copyright yukikaze,long.inus</div>";
+print
+"<div align=center data-role='footer'>Libre10 git '13Q2<BR>Copyright yukikaze,long.inus</div>";
print "</div>";
print $cgi->end_html;
use DBD::SQLite;
use Data::Dumper;
use Image::Magick;
+use YAML::XS;
+
#use KCatch;
#
# Libre10
# Copyright 2013 yukikaze,long.inus
#
$cgi = new CGI;
+my $confpath = "";
+if ( -e "libre10.conf" ) {
+ $confpath = "libre10.conf";
+}
+else {
+ $confpath = "/etc/libre10.conf";
+}
+$confdata = YAML::XS::LoadFile($confpath);
$pdfpath = decode( 'utf-8', $cgi->param('pdfpath') );
$pdfpath =~ s/\"//g;
$pagenum = int( $cgi->param('pagenum') );
$width = int( $cgi->param('width') );
$height = int( $cgi->param('height') );
$mode = $cgi->param('mode');
-$outputpath = "/tmp/rec10pdf/tmp" . generate_unique_key();
-$dbpath = "/tmp/libre10.db";
-$dbi = DBI->connect("dbi:SQLite:dbname=$dbpath","","",{RaiseError=>1,AutoCommit => 1});
-$dbi_state=$dbi->prepare("SELECT path FROM pdffile WHERE id='$pdfpath'");
+$outputpath = "/tmp/libre10/tmp" . generate_unique_key();
+$dbpath = $confdata->{dburl};
+$dbi =
+ DBI->connect( "dbi:SQLite:dbname=$dbpath", "", "",
+ { RaiseError => 1, AutoCommit => 1 } );
+$dbi_state = $dbi->prepare("SELECT path FROM pdffile WHERE id='$pdfpath'");
$dbi_state->execute();
+
#print $cgi->header;
#print $cgi->start_html;
#print Dumper $dbi;
-$pdfpath=$dbi_state->fetchrow_array;
+$pdfpath = $dbi_state->fetchrow_array;
$dbi->disconnect;
+
#print $pdfpath;
-if (-e "/tmp/rec10pdf"){
+if ( -e "/tmp/libre10" ) {
+
#"";
-}else{
- system "mkdir /tmp/rec10pdf";
+}
+else {
+ system "mkdir /tmp/libre10";
}
if ( ( -e $pdfpath ) && ( -r $pdfpath ) ) {
$b = $pagenum - $pagediff;
$b = 1;
}
system "pdfimages -f $pagenum -l $pagenum -j '$pdfpath' $outputpath";
- #print "pdfimages -f $pagenum -l $pagenum -j '$pdfpath' $outputpath";
}
$outputpathjpg = "$outputpath-000.jpg";
if ( $width > 0 && $height > 0 ) {
$outputpath_rs_jpg = "$outputpath-000-$width-$height.jpg";
- if ($mode eq 'im2'){
+ if ( $mode eq 'im2' ) {
generate_resized_image( $outputpathjpg, $outputpath_rs_jpg, $width,
- $height );
- }else{
- generate_resized_image_magick( $outputpathjpg, $outputpath_rs_jpg, $width,
- $height );
+ $height );
+ }
+ else {
+ generate_resized_image_magick( $outputpathjpg, $outputpath_rs_jpg,
+ $width, $height );
}
$outputpathjpg = $outputpath_rs_jpg;
}
-if (-e $outputpathjpg){
+if ( -e $outputpathjpg ) {
$size = -s $outputpathjpg;
print "Content-type: image/jpeg\n";
print "Content-length:", $size, "\n";
open( IN, $outputpathjpg );
binmode(IN);
binmode(STDOUT);
+
#read(IN,$buf,$size);
while ( read( IN, $buf, 1048576 ) ) {
print $buf;
print $cgi->header( -type => "text/html", -charset => "utf-8" );
print $cgi->start_html( -title => "rec10 pdf search", -lang => "ja-JP" );
print "error<br>";
- print "pdftk \"" . $pdfpath . "\" cat " . $b . "-" . $e . " output \"/tmp/rec10pdf/" . basename($pdfpath) . "\"";
+ print "pdftk \"$pdfpath\" cat $b - $e output \"/tmp/rec10pdf/ "
+ . basename($pdfpath) . "\"";
}
sub generate_unique_key {
}
elsif ( $width / $height < $img->width / $img->height ) {
$height = $width / $img->width * $img->height;
- }else{
- $width = $height / $img->height * $img ->width;
}
- $img = $img->create_scaled_image($width,$height);
+ else {
+ $width = $height / $img->height * $img->width;
+ }
+ $img = $img->create_scaled_image( $width, $height );
$img->set_quality(40);
$img->save($resized_img_path);
}
+
sub generate_resized_image_magick {
- my ( $img_path, $resized_img_path, $width, $height ) = @_;
- my $image = Image::Magick->new(size=>"$width".'x'."$height");
+ my ( $img_path, $resized_img_path, $width, $height ) = @_;
+ my $image = Image::Magick->new( size => "$width" . 'x' . "$height" );
$image->Read($img_path);
- my ($img_width,$img_height) = $image->Get('width','height');
- if ( $img_width < $width && $img_height < $height ) {
- $height = $img_height;
- $width = $img_width;
- }
- elsif ( $width / $height < $img_width / $img_height ) {
- $height = $width / $img_width * $img_height;
- }else{
- $width = $height / $img_height * $img_width;
- }
- $image->Set(quality=>40);
- #$image=$image->convert(preset => 'noalpha');
- $image->Resize(width=>$width,height=>$height,blur=>0.8);
- $image->Write($resized_img_path);
+ my ( $img_width, $img_height ) = $image->Get( 'width', 'height' );
+ if ( $img_width < $width && $img_height < $height ) {
+ $height = $img_height;
+ $width = $img_width;
+ }
+ elsif ( $width / $height < $img_width / $img_height ) {
+ $height = $width / $img_width * $img_height;
+ }
+ else {
+ $width = $height / $img_height * $img_width;
+ }
+
+ #$image->Trim();
+ $image->Set( quality => 40 );
+
+ #$image->Level();
+ #$image=$image->convert(preset => 'noalpha');
+ $image->Resize( width => $width, height => $height, blur => 0.8 );
+ $image->Write($resized_img_path);
+ system
+"jpegtran -progressive -copy none -outfile $resized_img_path.out -optimize $resized_img_path";
+ if ( -e "$resized_img_path.out" ) {
+ system "rm $resized_img_path";
+ system "mv $resized_img_path.out $resized_img_path";
+ }
}
use warnings;
use Data::Dumper;
use YAML::XS;
+
#use DBI;
#
# Libre10
$confpath = "/etc/libre10.conf";
}
$confdata = YAML::XS::LoadFile($confpath);
+
#my $sqlpath ="/tmp/libre10.db";
#$sqldbi = DBI->connect("dbi:SQLite.dbname=" . $sqlpath);
-my $q = new CGI;
-my $mode = "";
-my $search_text=$q->param("search_text");
-$mode = $q->param("mode");
-$width = $q->param("width");
+my $q = new CGI;
+my $mode = "";
+my $search_text = $q->param("search_text");
+$mode = $q->param("mode");
+$width = $q->param("width");
$height = $q->param("height");
my $url = $confdata->{solrurl};
my $solr = WebService::Solr->new($url);
print $q->header( -type => "text/html", -charset => "utf-8" );
-print $q->start_html( -title => "rec10 pdf search",
- -lang => "ja-JP",
- -script => {-type=>"text/javascript",-src=>"frame.js"},
- -style => {"src"=>"libre10.css"} );
+print $q->start_html(
+ -title => "rec10 pdf search",
+ -lang => "ja-JP",
+ -script => { -type => "text/javascript", -src => "frame.js" },
+ -style => { "src" => "libre10.css" }
+);
print "<form action=\"pdfsearch.pl\" method=\"get\">";
print "<div align=center><H1>Libre10 pdf search</H1></div>";
-print "<div align=center><p><input name='search_text' value='' style='width:200px'\/>";
+print
+"<div align=center><p><input name='search_text' value='' style='width:200px'\/>";
print "<input type=\"submit\" value=\"search\"/></p></div><hr>";
#print Dumper($confdata->{solrurl});
}
);
- #my $response = $solr->search($query,{'rows' => '100','fl'=>'title,text,page,path'});
- #my $response = $solr->search($query);
- #print "texst";
+#my $response = $solr->search($query,{'rows' => '100','fl'=>'title,text,page,path'});
+#my $response = $solr->search($query);
+#print "texst";
my $hits = $response->content;
my %hits = %$hits;
my $response_header = $hits{grouped}{title_group}{groups};
}
}
else {
+
#print "<a href=pdfsearch.pl?mode=$mode&width=1600>for Tablet</a><br>\n";
print "<div align=center>";
- print "<a href=pdfsearch.pl?mode=mobile&width=1024&height=1280>for narrow band</a><br>\n";
- print "<a href=pdfsearch.pl?mode=mobile&width=1600&height=2560>for Tablet</a><br>\n";
+ print
+"<a href=pdfsearch.pl?mode=mobile&width=1024&height=1280>for narrow band</a><br>\n";
+ print
+"<a href=pdfsearch.pl?mode=mobile&width=1600&height=2560>for Tablet</a><br>\n";
- #print "<a href=pdfsearch.pl?mode=$mode&width=540>SmartPhone(w540)</a><br>\n";
- print "<a href=pdfsearch.pl?mode=mobile&width=1080&height=1920>for SmartPhone</a><br>\n";
- print "<a href=pdfsearch.pl?mode=mobile&width=1600&height=2100>for Tablet retina</a><br>\n";
- print "<a href=pdfsearch.pl?mode=mobile&width=1280&height=2400>for SmartPhone retina</a><br>\n";
+ #print "<a href=pdfsearch.pl?mode=$mode&width=540>SmartPhone(w540)</a><br>\n";
+ print
+"<a href=pdfsearch.pl?mode=mobile&width=1080&height=1920>for SmartPhone</a><br>\n";
+ print
+"<a href=pdfsearch.pl?mode=mobile&width=1600&height=2100>for Tablet retina</a><br>\n";
+ print
+"<a href=pdfsearch.pl?mode=mobile&width=1280&height=2400>for SmartPhone retina</a><br>\n";
print "<a href=pdfsearch.pl?mode=''>for PC(default)</a><br>\n";
print "</div>";
}
-print "<input type='hidden' name='mode' value=" . $mode . " >\n";
+print "<input type='hidden' name='mode' value=" . $mode . " >\n";
print "<input type='hidden' name='height' value=" . $height . " >\n";
-print "<input type='hidden' name='width' value=" . $width . " >\n";
+print "<input type='hidden' name='width' value=" . $width . " >\n";
#print $url;
#print Dumper($mode);
print "<p><h2>$title</h2> - $hitsnum 件の合致<br>";
foreach $doc (@$hits) {
- #print $doc->{text};
- #$sqldbi->prepare("SELECT path FROM pdffile WHERE id=" . $doc->{$path_id});
- ($pagenum,$path,$linkpath)=($doc->{page},$doc->{path_id},$doc->{path_id});
- print "page " . $pagenum ."<br>";
+ #print $doc->{text};
+ #$sqldbi->prepare("SELECT path FROM pdffile WHERE id=" . $doc->{$path_id});
+ ( $pagenum, $path, $linkpath ) =
+ ( $doc->{page}, $doc->{path_id}, $doc->{path_id} );
+ print "page " . $pagenum . "<br>";
+
#print Dumper($hits_hl->{$doc->{id}}{text});
print " " . $hits_hl->{ $doc->{id} }{text}[0] . "<br>";
print "<a href=\"htmlserver.pl?pdfpath=$path";
print "</p>\n";
}
}
+
#$sqldbi.disconnect;