Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

pick one random page instead of processing the whole document

  • Loading branch information...
commit f11637cfe9e352171aec9ff7ce88b79336df7bfc 1 parent e7c7f0c
@darkstalker authored
Showing with 8 additions and 1 deletion.
  1. +8 −1 rnd_ebooks.pl
View
9 rnd_ebooks.pl
@@ -28,8 +28,15 @@
my $pdf_selected = $pdf_list[int(rand($#pdf_list+1))];
print "selected file: $pdf_selected\n";
+# get page count
+my $page_count = (split ' ', `pdfinfo "$pdf_selected" | grep Pages`)[1];
+
+# select a random page
+my $sel_page = int(rand($page_count)) + 1;
+print "selected page: $sel_page / $page_count\n";
+
# extract raw text from pdf file
-my @lines = split "\n", decode('utf8', `pdftotext "$pdf_selected" - 2> /dev/null`);
+my @lines = split "\n", decode('utf8', `pdftotext -f $sel_page -l $sel_page "$pdf_selected" - 2> /dev/null`);
sub trim { $_[0] =~ s/^\s+//; $_[0] =~ s/\s+$//; $_[0]; }
Please sign in to comment.
Something went wrong with that request. Please try again.