-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakegdocs
executable file
·61 lines (49 loc) · 1.53 KB
/
makegdocs
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
#!/usr/bin/perl
# docs.google.com can convert/OCR pdf files under 11MB to word, so split a folder with images into pdfs with the max size of 11MB
# next upload to google drive and open with google docs each
# from outside a dir with jpg or png files
# makepdf dir_with_jpg_files
# will run all jpg or png files
use strict;
use warnings;
use Cwd;
my $cwd = cwd;
#use Sysadm::Install qw(qquote);
# Max files size that gdocs will convert: 11MB
use constant MAX_SIZE => (1024*1024*11);
my $dir = shift || ".";
chdir $dir;
my @img = map { qq[$dir/$_] } sort <*jpg>, <*jpeg>, <*png>, <*gif>, <*tiff>, <*tif>, <*JPG>, <*JPEG>, <*PNG>, <*GIF>, <*TIFF>, <*TIF>, <*/*jpg>, <*/*jpeg>, <*/*png>, <*/*gif>, <*/*tiff>, <*/*tif>, <*/*JPG>, <*/*JPEG>, <*/*PNG>, <*/*GIF>, <*/*TIFF>, <*/*TIF>;;
chdir $cwd;
#die join " ", $dir, @img;
my $output = "output.pdf";
$output = "$dir" if $dir ne ".";
my @pdfs = ();
my $c = 0;
my $total = 0;
my @list = ();
my $full = 0;
while (@img) {
my $sz = -s $img[0];
#print "size $sz\n";
if (($total + $sz) < MAX_SIZE) {
push @list, map { qq["$_"] } shift @img;
$total += $sz;
#print "filling $total $sz\n";
}
else {
$full = 1;
}
if ($full or not @img) {
$c++;
#print "ok, $total, @list\n";
#die MAX_SIZE, $total, @list;
my $f = sprintf "$output-%02d.pdf", $c;
my $cmd = qq[convert -define pdf:use-trimbox=true @list "$f"];
print "$cmd\n";
system $cmd;
$total = 0;
@list = ();
$full = 0;
}
}