From db7ba9053079944bf861220ed18a1d77604a0c5b Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Mon, 1 May 2023 11:23:54 -0400 Subject: [PATCH] Switch from pdftk to pdfinfo pdftk is no longer packaged for Alpine Linux and has an odd license. pdfinfo is part of poppler which is licensed under GPL. --- docker/Dockerfile | 2 +- docker/Dockerfile.alpine | 2 +- lib/Libki/Utils/Printing.pm | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index 26c2e222..fbca4a87 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -40,7 +40,7 @@ RUN install_packages \ libcups2-dev \ libcupsfilters-dev \ # Needed to count pages in encrypted PDFs - pdftk \ + poppler-utils \ # Print uploads filetype detection shared-mime-info diff --git a/docker/Dockerfile.alpine b/docker/Dockerfile.alpine index dfcfdfaa..624ba46c 100644 --- a/docker/Dockerfile.alpine +++ b/docker/Dockerfile.alpine @@ -31,7 +31,6 @@ RUN apk add --no-cache \ imagemagick \ imagemagick-perlmagick \ mysql-client \ - pdftk \ perl-app-cpanminus \ perl-dbd-mysql \ perl-dev \ @@ -47,6 +46,7 @@ RUN apk add --no-cache \ perl-params-validate \ perl-posix-strftime-compiler \ perl-yaml-xs \ + poppler-utils \ sed \ shared-mime-info \ wget diff --git a/lib/Libki/Utils/Printing.pm b/lib/Libki/Utils/Printing.pm index f613162b..14368743 100644 --- a/lib/Libki/Utils/Printing.pm +++ b/lib/Libki/Utils/Printing.pm @@ -62,12 +62,11 @@ sub create_print_job_and_file { my $pdf = PDF::API2->open_scalar($pdf_string); $pages = $pdf->pages(); } - catch { # PDF may be encrypted, try using pdftk instead + catch { # PDF may be encrypted, try using pdfinfo instead my ( $fh, $fn ) = tempfile(); write_file( $fn, $pdf_string ); - my $output = qx{ pdftk $fn dump_data | grep NumberOfPages }; - $output =~ m/NumberOfPages: (\d+)/; - $pages = $1; + my $pages = qx{ pdfinfo $fn | awk '/^Pages:/ {print \$2}' }; + chomp $pages; }; my $printers = $c->get_printer_configuration;