1

I have installed pdftk using snap in Ubuntu 18.04:

sudo snap install pdftk

In my home folder pdftk works fine:

root@localhost:/home# a.pdf output secure.128.pdf owner_pw 123456

root@localhost:/home# ls a.pdf secure.128.pdf

But in the /var/www folder it doesn't work:

root@localhost:/var/www/multi/pdfs# ls
a.pdf

root@localhost:/var/www/multi/pdfs# pdftk a.pdf output secure.128.pdf owner_pw 123456 Error: Unable to find file. Error: Failed to open PDF file: a.pdf Errors encountered. No output created. Done. Input errors, so no output created.

hous
  • 225

1 Answers1

0

As steeldriver commented, this is probably related to pdftk being installed as a snap application. If you want, you may check the post steeldriver linked to see if the pdftk snap is built with support to access files outside ~.

I suggest that you use the non-snap version of pdftk. Unfortunately, Ubuntu 18.04 does not include pdftk in its default repositories (thankfully, 20.04 has it), so it has to be built from source. I'm quoting the relevant part of David Foerster's answer for how to build it:

  1. Install the build tools and dependencies:

    sudo apt install git default-jdk-headless ant \
        libcommons-lang3-java libbcprov-java
    

    Of course you can use a different supported JDK than the one supplied by default-jdk-headless.

  2. Download Marc Vinyal’s pdftk fork:

    git clone https://gitlab.com/pdftk-java/pdftk.git
    cd pdftk
    
  3. Place symbolic links to the required libraries into the lib folder:

    mkdir lib
    ln -st lib /usr/share/java/{commons-lang3,bcprov}.jar
    
  4. Build the JAR package:

    ant jar
    
  5. Run the JAR package:

    java -jar build/jar/pdftk.jar --help
    
  6. (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 libraries libcommons-lang3-java and libbcprov-java:

    sudo apt install default-jre-headless libcommons-lang3-java libbcprov-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).

  7. (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.