Is there any chance of getting pdftk
working in Ubuntu 18.04?
I need this for creating PDF files with a watermark in shell.
Or, does anybody know a working alternative to pdftk
to generate a PDF with a watermark in shell?
I already check/try out all of them:
sudo apt list pdf*
Listing... Done
pdf-presenter-console/bionic 4.1-2 amd64
pdf-redact-tools/bionic,bionic 0.1.2-1 all
pdf.js-common/bionic,bionic 1.5.188+dfsg-1 all
pdf2djvu/bionic 0.9.8-0ubuntu1 amd64
pdf2svg/bionic 0.2.3-1 amd64
pdfcrack/bionic 0.16-1 amd64
pdfcube/bionic 0.0.5-2build6 amd64
pdfcube-dbg/bionic 0.0.5-2build6 amd64
pdfgrep/bionic 2.0.1-1 amd64
pdfminer-data/bionic,bionic 20140328+dfsg-1 all
pdfmod/bionic,bionic 0.9.1-8 all
pdfmod-dbg/bionic,bionic 0.9.1-8 all
pdfposter/bionic,bionic 0.6.0-2 all
pdfresurrect/bionic 0.14-1 amd64
pdfsam/bionic,bionic 3.3.5-1 all
pdfsandwich/bionic 0.1.6-1 amd64
pdfshuffler/bionic,bionic 0.6.0-8 all
pdftoipe/bionic 1:7.2.7-1build1 amd64
But did not find a working tool.
The pdftk package in Ubuntu (and its upstream Debian package) was dropped due to its dependency on the now deprecated GCJ runtime. I found a fork that depends on OpenJDK or similar instead.
Install from a future Ubuntu release (recommended)
Starting with Cosmic (Ubuntu 18.10), Ubuntu ships
pdftk-java
from the same source code as below as a replacement. Attempting to installpdftk
will install this package instead. Users of earlier releases can download it manually from the package repository and install it with their favourite package manager.Install from PPA(outdated)I built a Deb package (for Bionic only) with suitable dependencies:The package contains a wrapper script placed in
/usr/bin
, so you can invoke it as normally:Install from source
Install the build tools and dependencies:
Of course you can use a different supported JDK than the one supplied by
default-jdk-headless
.Download Marc Vinyal’s pdftk fork:
Place symbolic links to the required libraries into the
lib
folder:Build the JAR package:
Run the JAR package:
(Optional) To run the JAR package, e. g. when you distribute it to other systems, you need at least a working (headless) JRE like from the
default-jre-headless
package as well as the Java librarieslibcommons-lang3-java
andlibbcprov-java
:Again you can use a different JRE than
default-jre-headless
. This pdftk fork also supports builds for older JRE versions (≥ 7 according to the documentation).(Optional) You can teach Linux to execute JAR (Java Archive) files via
update-binfmts(8)
. Most JREs shipped in Deb packages, including those in Canonical’s package repositories, take care of that during installation, though it appears to be buggy in some OpenJDK packages.P.S.: I tried this with the non-headless OpenJDK 9 in Ubuntu Trusty but I see little reasons why it shouldn't work with headless OpenJDK 10 in Bionic.
Depending applications
A commenter raised the valid question whether the depending PDF Chain applications is affected by this change:
For Ubuntu 18.04, just install the pdftk snap package:
Installing pdftk on Ubuntu 18.04 amd64
I've written a small bash script which automatise the installation on Ubuntu 18.04. Note that I've downloaded only amd64 packages!
This script will download the packages to
/tmp
and install from there using anapt install
command! Afterwards the packages in the/tmp
directory will be removed.To run this script, copy it in an editor and save it e.g. pdftk_installer. Then run it in a terminal with
Installing pdftk on Ubuntu 20.04 amd64
The script above will fail due to missing gcc-6 libraries on Ubuntu 20.04. However, those who would like to avoid the snap or docker solution may use schroot. I know that this is a pretty overload - it takes about 500MB; but you can use this environment to install further elderly programs, libs, compilers, etc. in the Xenial (Ubuntu 16.04) environment.
First install the
schroot
packageThe last package is required to install a debian-like-system. Now write a
xenial.conf
file into the/etc/schroot/schroot.d
directory:Verify that the new conf-file is written
Next create the xenial directory (if you choose another directory alter the conf file above):
Now the show begins, while installing go for a coffee:
The xenial file system is now available on
/srv/chroot/xenial
.Now it's time to include the necessary xenial apt repositories. To do so type
Again check that the file
/srv/chroot/xenial/etc/apt/sources.list
existsIt's time to enter the xenial schroot (note: no root privileges needed!) and update the apt
Finally you are ready to install the
pdftk package
:You can use
pdftk
by invoking it via the schroot:E.g. to show the help menu type
Last of all I suggest to make an alias for pdftk in your
.bashrc
file:First make a copy of your .bashrc
and then add an alias
Now you can use
pdf
as usual in your bash. To test open a new terminal and typeIf you have to install other older programs as I had to do, use the apt commands similar as described above.
Note that all commands beside the
apt-get
and thexenial.config
are executed with user privileges.This works for ubuntu 18.04:
You can try use a docker image of Ubuntu 16.04 with pdftk installed to run pdftk:
Install docker:
Pull Ubuntu 16.04 and run a bash shell:
Update and install pdftk from container prompt:
On a new terminal run:
Commit the image using the CONTAINER ID of ubuntu:16.04 to a new image with pdftk installed:
(Replace
CONTAINER_ID
with your container ID.)Create a file named
pdftk
in/usr/bin
and then make it executable usingchmod +x /usr/bin/pdftk
:Install the pdftk snap package.
Run:
Do as follows to run your package from root or you want to run from node, etc.
Once you install Pdftk from snap you need to change the path
/snap/pdftk/current/usr/..
to Ubuntu to/usr
for replace run the following command.or for overwrite run the following command.
Test with
pdftk input.pdf cat output new.pdf
I was able to install pdftk from artful (17.10) deb packages. Download and then install, in that order :
It's best to install
gcc-6-base
first to avoid dependencies error if you do it from cli.That should do the trick… for now.
I made a quick and dirty workaround to get PDFTK running under Bionic.
I update my
sources.list
and include the following lines:After that I run a simple
to make the changes take effect.
Then install pdftk via
Then remove the Artful sources from the source.list again and this is how I get PDFTK running under Bionic.
Source: https://christiandietze.de/pdftk-with-ubuntu-bionic-18-04/
I like Ademir's docker answer, but it has the typical problems with security and permissions, because docker has to run as root. If that bothers you, try using Singularity. You need to build the image as root, but any user can then run it.
Here's the
Singularity
file I used:Then I built the image.
Once that worked, I installed it to a folder on the path, along with a wrapper script that sets the home folder to the current directory.
And now I can run
pdftk
.The only down side is that it's a rather large executable, because it contains a complete Ubuntu 16.04 distribution. You might also have trouble if you're trying to manipulate PDF files that aren't in the current directory.
For getting pdftk onto 18.04 specifically, I've found that this works:
pdftk-java
IE: