App-PDFUtils
view release on metacpan or search on metacpan
lib/App/PDFUtils.pm view on Meta::CPAN
#require Proc::ChildError;
#require Path::Tiny;
my %args = @_;
my $envres = envresmulti();
FILE:
for my $f (@{ $args{files} }) {
unless (-f $f) {
$envres->add_result(404, "File not found", {item_id=>$f});
next FILE;
}
# XXX test that tempfile doesn't yet exist. but actually we can't avoid
# race condition because qpdf is another process
(my $tempf = $f) =~ s/\.pdf$/".tmp_" . int(rand()*900_000 + 100_000) . ".pdf"/ei
or do {
$envres->add_result(412, "Cannot set temporary name for $f");
next FILE;
};
lib/App/PDFUtils.pm view on Meta::CPAN
#require Proc::ChildError;
#require Path::Tiny;
my %args = @_;
my $envres = envresmulti();
FILE:
for my $f (@{ $args{files} }) {
unless (-f $f) {
$envres->add_result(404, "File not found", {item_id=>$f});
next FILE;
}
# XXX test that tempfile doesn't yet exist. but actually we can't avoid
# race condition because qpdf is another process
(my $tempf = $f) =~ s/\.pdf$/".tmp_" . int(rand()*900_000 + 100_000) . ".pdf"/ei
or do {
$envres->add_result(412, "Cannot set temporary name for $f");
next FILE;
};
lib/App/PDFUtils.pm view on Meta::CPAN
sub compress_pdf {
require IPC::System::Options;
my %args = @_;
my $envres = envresmulti();
FILE:
for my $f (@{ $args{files} }) {
unless (-f $f) {
$envres->add_result(404, "File not found", {item_id=>$f});
next FILE;
}
my $outputf = $f;
$outputf =~ s/\.(pdf)\z/.compressed.$1/i or do {
$envres->add_result(500, "Cannot determine output filename", {item_id=>$f});
next FILE;
};
if ((-f $outputf) && !$args{overwrite}) {
$envres->add_result(412, "Won't overwrite existing output $outputf", {item_id=>$f});
next FILE;
( run in 1.321 second using v1.01-cache-2.11-cpan-39bf76dae61 )