2

As pdftk is not yet available on Ubuntu 18.04 I compiled a pdftk fork following this excellent answer to a related question.

This works great, however I now have to type

java -jar build/jar/pdftk.jar

to run pdftk.

I would like to just type pdftk with its respective options. I created a bash script, but this does ignore the command line options. Any ideas?

dessert
  • 39,392
  • 12
  • 115
  • 163
Bruni
  • 10,180
  • 7
  • 55
  • 97

2 Answers2

2

That's a case for alias: Open ~/.bash_aliases in your preferred text editor and add this line:

alias pdftk='java -jar build/jar/pdftk.jar'

Save the file and open up a new terminal window (or run . ~/.bash_aliases in an existing), pdftk should work with the syntax as you know it now.

dessert
  • 39,392
  • 12
  • 115
  • 163
  • I am not sure why you have added an answer while there is a similar duplicate question tagged already – Raja G May 01 '18 at 11:50
  • Can I just create such a file if it does not exist? I would prefer not writing this directly in .bashrc – Bruni May 01 '18 at 11:52
  • @Bruni Yes, or add the line to `~/.bashrc` instead – as you like. – dessert May 01 '18 at 11:52
  • @Ten-Coin Simply because I'm not sure it suffices. There seems to be a concensus that this isn't a problem, see [this meta question](https://meta.askubuntu.com/q/3608/507051), especially [this answer](https://meta.askubuntu.com/a/15946/507051) and the discussion in the comments. – dessert May 01 '18 at 11:56
1

Here a bash script for you

#!/bin/bash

exec java -jar /path/to/pdftk.jar "$@"

$@ is the variable you were looking for. It's all the argument you pass to the script that you pass on to pdftk.jar.

exec is to avoid another shell and replace it with java process.

solsTiCe
  • 9,071
  • 3
  • 36
  • 64