Skip to content

Instantly share code, notes, and snippets.

@bmaupin
Last active October 10, 2023 15:37
Show Gist options
  • Save bmaupin/a23161b50f27179e6e5b064d6066b034 to your computer and use it in GitHub Desktop.
Save bmaupin/a23161b50f27179e6e5b064d6066b034 to your computer and use it in GitHub Desktop.
Run PDFEdit in Docker (was Install PDFEdit on Ubuntu)

Run PDFEdit in Docker

(Recommended) Use x11docker

  1. Install x11docker

    https://github.com/mviereck/x11docker

  2. Run PDFEdit, e.g

    x11docker --share "$PWD" ghcr.io/bmaupin/pdfedit
    

    --share "$PWD" will share your current directory with PDFEdit so you can see files from your PC

Run without x11docker

This is a lot more complicated and not secure.

There are many ways to do this, here's just one example:

  1. CD to the directory containing the PDF to edit

  2. Run PDFEdit

    xhost +; docker run --rm -v "$PWD:/workdir" -e DISPLAY=$DISPLAY -v "$HOME/.Xauthority:/root/.Xauthority:rw" --net=host ghcr.io/bmaupin/pdfedit; xhost -
    

Dockerfile

This is the Dockerfile that was used to create the ghcr.io/bmaupin/pdfedit image:

FROM ubuntu:12.04

WORKDIR /workdir

# Change the default shell to bash
SHELL ["/bin/bash", "-c"]

# Curl command from https://unix.stackexchange.com/a/421318/14436
RUN echo -e 'function __curl() { \n  read proto server path <<<$(echo ${1//// }) \n  DOC=/${path// //} \n  HOST=${server//:*} \n  PORT=${server//*:} \n  [[ x"${HOST}" == x"${PORT}" ]] && PORT=80 \n  exec 3<>/dev/tcp/${HOST}/$PORT \n  echo -en "GET ${DOC} HTTP/1.0\\r\\nHost: ${HOST}\\r\\n\\r\\n" >&3 \n  (while read line; do \n   [[ "$line" == $'"'"'\\r'"'"' ]] && break \n  done && cat) <&3 \n  exec 3>&- \n}' > curl.sh

# TODO: use __curl to get wget or curl or something better for better output if one of the below downloads fails ...

RUN source curl.sh && \
  __curl http://launchpadlibrarian.net/389235809/liblcms1_1.19.dfsg-1ubuntu3.1_amd64.deb > liblcms1_1.19.dfsg-1ubuntu3.1_amd64.deb && \
  __curl http://launchpadlibrarian.net/83092708/libmng1_1.0.10-3_amd64.deb > libmng1_1.0.10-3_amd64.deb && \
  __curl http://launchpadlibrarian.net/377985985/libpng12-0_1.2.46-3ubuntu4.3_amd64.deb > libpng12-0_1.2.46-3ubuntu4.3_amd64.deb && \
  __curl http://launchpadlibrarian.net/86479683/libqt3-mt_3.3.8-b-8ubuntu3_amd64.deb > libqt3-mt_3.3.8-b-8ubuntu3_amd64.deb && \
  __curl http://launchpadlibrarian.net/58578046/pdfedit_0.4.5-2_amd64.deb > pdfedit_0.4.5-2_amd64.deb && \
  __curl http://launchpadlibrarian.net/279293539/fontconfig_2.8.0-3ubuntu9.2_amd64.deb > fontconfig_2.8.0-3ubuntu9.2_amd64.deb && \
  __curl http://launchpadlibrarian.net/149258100/libaudio2_1.9.3-4ubuntu0.1_amd64.deb > libaudio2_1.9.3-4ubuntu0.1_amd64.deb && \
  __curl http://launchpadlibrarian.net/279293538/libfontconfig1_2.8.0-3ubuntu9.2_amd64.deb > libfontconfig1_2.8.0-3ubuntu9.2_amd64.deb && \
  __curl http://launchpadlibrarian.net/440576614/libfreetype6_2.4.8-1ubuntu2.7_amd64.deb > libfreetype6_2.4.8-1ubuntu2.7_amd64.deb && \
  __curl http://launchpadlibrarian.net/94947351/libice6_1.0.7-2build1_amd64.deb > libice6_1.0.7-2build1_amd64.deb && \
  __curl http://launchpadlibrarian.net/94579504/libjpeg8_8c-2ubuntu7_amd64.deb > libjpeg8_8c-2ubuntu7_amd64.deb && \
  __curl http://launchpadlibrarian.net/94947900/libsm6_1.2.0-2build1_amd64.deb > libsm6_1.2.0-2build1_amd64.deb && \
  __curl http://launchpadlibrarian.net/496048808/libx11-6_1.4.99.1-0ubuntu2.5_amd64.deb > libx11-6_1.4.99.1-0ubuntu2.5_amd64.deb && \
  __curl http://launchpadlibrarian.net/140925309/libxcursor1_1.1.12-1ubuntu0.1_amd64.deb > libxcursor1_1.1.12-1ubuntu0.1_amd64.deb && \
  __curl http://launchpadlibrarian.net/203090918/libxext6_1.3.0-3ubuntu0.2_amd64.deb > libxext6_1.3.0-3ubuntu0.2_amd64.deb && \
  __curl http://launchpadlibrarian.net/94948951/libxft2_2.2.0-3ubuntu2_amd64.deb > libxft2_2.2.0-3ubuntu2_amd64.deb && \
  __curl http://launchpadlibrarian.net/203091986/libxi6_1.7.1.901-1ubuntu1~precise3_amd64.deb > libxi6_1.7.1.901-1ubuntu1~precise3_amd64.deb && \
  __curl http://launchpadlibrarian.net/140930018/libxinerama1_1.1.1-3ubuntu0.1_amd64.deb > libxinerama1_1.1.1-3ubuntu0.1_amd64.deb && \
  __curl http://launchpadlibrarian.net/203094691/libxrandr2_1.3.2-2ubuntu0.3_amd64.deb > libxrandr2_1.3.2-2ubuntu0.3_amd64.deb && \
  __curl http://launchpadlibrarian.net/202510483/libxrender1_0.9.6-2ubuntu0.2_amd64.deb > libxrender1_0.9.6-2ubuntu0.2_amd64.deb && \
  __curl http://launchpadlibrarian.net/279293542/fontconfig-config_2.8.0-3ubuntu9.2_all.deb > fontconfig-config_2.8.0-3ubuntu9.2_all.deb && \
  __curl http://launchpadlibrarian.net/442009060/libexpat1_2.0.1-7.2ubuntu1.7_amd64.deb > libexpat1_2.0.1-7.2ubuntu1.7_amd64.deb && \
  __curl http://launchpadlibrarian.net/483376388/libjpeg-turbo8_1.1.90+svn733-0ubuntu4.6_amd64.deb > libjpeg-turbo8_1.1.90+svn733-0ubuntu4.6_amd64.deb && \
  __curl http://launchpadlibrarian.net/496048599/libx11-data_1.4.99.1-0ubuntu2.5_all.deb > libx11-data_1.4.99.1-0ubuntu2.5_all.deb && \
  __curl http://launchpadlibrarian.net/84788368/libxau6_1.0.6-4_amd64.deb > libxau6_1.0.6-4_amd64.deb && \
  __curl http://launchpadlibrarian.net/140864111/libxcb1_1.8.1-1ubuntu0.2_amd64.deb > libxcb1_1.8.1-1ubuntu0.2_amd64.deb && \
  __curl http://launchpadlibrarian.net/203092202/libxfixes3_5.0-4ubuntu4.4_amd64.deb > libxfixes3_5.0-4ubuntu4.4_amd64.deb && \
  __curl http://launchpadlibrarian.net/141012031/libxt6_1.1.1-2ubuntu0.1_amd64.deb > libxt6_1.1.1-2ubuntu0.1_amd64.deb && \
  __curl http://launchpadlibrarian.net/127495438/x11-common_7.6+12ubuntu2_all.deb > x11-common_7.6+12ubuntu2_all.deb && \
  __curl http://launchpadlibrarian.net/70775788/gsfonts-x11_0.22_all.deb > gsfonts-x11_0.22_all.deb && \
  __curl http://launchpadlibrarian.net/84805563/libxdmcp6_1.1.0-4_amd64.deb > libxdmcp6_1.1.0-4_amd64.deb && \
  __curl http://launchpadlibrarian.net/52149269/ttf-bitstream-vera_1.10-8_all.deb > ttf-bitstream-vera_1.10-8_all.deb && \
  __curl http://launchpadlibrarian.net/100987553/ttf-dejavu-core_2.33-2ubuntu1_all.deb > ttf-dejavu-core_2.33-2ubuntu1_all.deb && \
  __curl http://launchpadlibrarian.net/70804192/ttf-freefont_20100919-1_all.deb > ttf-freefont_20100919-1_all.deb && \
  __curl http://launchpadlibrarian.net/71073801/ucf_3.0025+nmu2ubuntu1_all.deb > ucf_3.0025+nmu2ubuntu1_all.deb && \
  __curl http://launchpadlibrarian.net/56199369/gsfonts_8.11+urwcyr1.0.7~pre44-4.2ubuntu1_all.deb > gsfonts_8.11+urwcyr1.0.7~pre44-4.2ubuntu1_all.deb && \
  __curl http://launchpadlibrarian.net/74357981/xfonts-utils_7.6+1_amd64.deb > xfonts-utils_7.6+1_amd64.deb && \
  __curl http://launchpadlibrarian.net/59359929/libfontenc1_1.1.0-1_amd64.deb > libfontenc1_1.1.0-1_amd64.deb && \
  __curl http://launchpadlibrarian.net/200541371/libxfont1_1.4.4-1ubuntu0.3_amd64.deb > libxfont1_1.4.4-1ubuntu0.3_amd64.deb && \
  __curl http://launchpadlibrarian.net/97312039/xfonts-encodings_1.0.4-1ubuntu1_all.deb > xfonts-encodings_1.0.4-1ubuntu1_all.deb

RUN dpkg -i *.deb && \
  rm -rf *.deb curl.sh

CMD pdfedit

Old instructions

⚠ These steps no longer work. The links are broken (see above for working links), but the bigger issue is that the packages are too old to work in a modern version of Ubuntu.

sudo -v

# Setup
mkdir tmp
cd tmp

# Install PDFEdit and dependencies
wget http://mirrors.kernel.org/ubuntu/pool/main/l/lcms/liblcms1_1.19.dfsg-1ubuntu3_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/libm/libmng/libmng1_1.0.10-3_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/main/q/qt-x11-free/libqt3-mt_3.3.8-b-8ubuntu3_amd64.deb
wget http://mirrors.kernel.org/ubuntu/pool/universe/p/pdfedit/pdfedit_0.4.5-2_amd64.deb
sudo dpkg -i *.deb

# Cleanup
rm *.deb
cd ..
rmdir tmp

# To uninstall:
# sudo apt autoremove liblcms1 libmng1 libpng12-0 libqt3-mt pdfedit
@CanViet
Copy link

CanViet commented May 20, 2017

The installation was good, is there any problem by not using temp folder to set-up, can the clean-up still be performed?
Thanks

@bmaupin
Copy link
Author

bmaupin commented Jun 9, 2017

Yeah, so I created the temp folder for easier installation (dpkg -i *.deb) and cleanup (rm *.deb). Otherwise you'd have to install and remove each package individually to make sure you don't accidentally delete any other .deb files in the folder where you run the script. It's also nice to have everything in one folder so if the script aborts you can clean up without having to sift through other files in the working directory.

So to answer your question it's not necessary, it just makes things a little easier.

@dungsaga
Copy link

dungsaga commented Sep 5, 2017

libjpeg62 is not required here. Because libqt3-mt and libqt3-mt depend on libjpeg8 which is available in Ubuntu 16.04.

@USRFSledge
Copy link

libjpeg62 is not required here

I can confirm this comment from dungsaga. Works like a charm without libjpeg62

@bmaupin
Copy link
Author

bmaupin commented Jan 20, 2018

@dungsaga @USRFSledge I removed that line, thanks for the heads up!

@JulianKunkel
Copy link

Thanks, does also work with 18.04 with minor extension:
Needs libpng12, too:
wget http://fr.archive.ubuntu.com/ubuntu/pool/main/libp/libpng/libpng12-0_1.2.54-1ubuntu1_amd64.deb

I would love if someone actually maintains a proper package or a PPA, but I guess that is true for everyone.

@AntiSol
Copy link

AntiSol commented May 8, 2018

Thanks for this, was very helpful. It's disappointing how much software was removed from the repos between 14.04 and 16.04.

@VincentTam
Copy link

@JulianKunkel Thanks for your message. I confirm @AntiSol's observation

@bmaupin
Copy link
Author

bmaupin commented Oct 24, 2018

@stela2502
Copy link

You could change the line

Tested on Ubuntu 16.04

to

Tested on Ubuntu 16.04 and 18.04.4

@rabagliati
Copy link

Tested on Ubuntu 20.04 - it works

@wwone
Copy link

wwone commented May 2, 2020

I fear that installing pdfedit may have broken the rest of my
system. I'm running Ubuntu with "lubuntu" as my desktop
environment.

uname -a yields:

Linux bobpenguin 4.15.0-96-generic #97~16.04.1-Ubuntu SMP Wed Apr 1 03:03:31 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

When I try to perform any system updates now, I get a large
number of errors, including:

The following packages have unmet dependencies:
libpng12-0 : Breaks: libpng12-0:i386 (!= 1.2.54-1ubuntu1) but 1.2.54-1ubuntu1.1 is installed
libpng12-0:i386 : Breaks: libpng12-0 (!= 1.2.54-1ubuntu1.1) but 1.2.54-1ubuntu1 is installed

Most packages will no longer update, as there seems to be a conflict between libpng, libqt3,
and many existing programs.

Help?

@bmaupin
Copy link
Author

bmaupin commented May 2, 2020

@wwone I'd recommend uninstalling one of the libpng12-0 packages and seeing if it fixes the problem. Maybe remove the i386 one since you're running a 64-bit OS?:

sudo apt remove libpng12-0:i386

There's always a risk of package conflicts when installing things manually. If that doesn't work, it might be best just to uninstall this (see the last line of the script above) and use a different product. One I've used with success in the past to edit PDFs is Master PDF Editor: https://code-industry.net/free-pdf-editor/

It used to be free to edit PDFs with, although apparently starting with version 5 this is a paid feature. It's possible you can still edit PDFs with it and it will add a watermark. Alternatively, you can probably find a package for version 4 somewhere on the internet. Here are some of the v4 package names that you might use to search in case it helps :)

  • master-pdf-editor-4.3.82_qt5.amd64.deb
  • master-pdf-editor-4.3.61_qt5.amd64.deb
  • master-pdf-editor-4.2.70_qt5.amd64.deb
  • master-pdf-editor-4.1.30_qt5.amd64.deb
  • master-pdf-editor-4.1.01_qt5.amd64.deb
  • master-pdf-editor-4.0.30_qt5.amd64.deb

If you need further help, I'd recommend asking here: https://askubuntu.com/

Cheers!

@wwone
Copy link

wwone commented May 2, 2020

Thanks for the assistance. I tried removing the 32-bit libpng as suggested, and got:

You might want to run 'apt-get -f install' to correct these:
The following packages have unmet dependencies:
libfreetype6:i386 : Depends: libpng12-0:i386 (>= 1.2.13-4) but it is not going to be installed
libgd3:i386 : Depends: libpng12-0:i386 (>= 1.2.13-4) but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).

This may not be worth pursuing, except that installation of general Ubuntu patches and updates seems to be jammed by these errors.

Regarding PDF handling, I have enough Java knowledge to be able to use PDFBOX. Even for users without specific Java skills, this suite of stand-alone programs and Java libraries is very rich. For instance, I was able to programmatically "cleanse" some IRS forms, so that our office could actually perform form fill-in using them. I regularly use both my own created Java programs, as well as the command-line programs offered by this great package.

https://pdfbox.apache.org/

Your advice is greatly appreciated!

@bmaupin
Copy link
Author

bmaupin commented Jun 21, 2020

I know this isn't something you asked for, but in case it helps somebody else, it seems the latest official packages for Master PDF Editor 4 are still available from the vendor's site. I'm not personally comfortable downloading random packages off the internet so I was excited to see these still available from the official source.

(Source: https://www.linuxuprising.com/2019/04/download-master-pdf-editor-4-for-linux.html)

@wwone
Copy link

wwone commented Jun 21, 2020

Thanks for the link. I had to perform a clean install, which at least got me up to Ubuntu 20 and stopped all of the update errors. I did not try to use "pdfedit", and am now successfully using "pdftk" for my needs. When anything more esoteric is needed, I can still fall back on the Java system "PDFBox".

@katiakweb
Copy link

Works perfectly in Ubuntu 20.04. Thanks!

@moi90
Copy link

moi90 commented Dec 2, 2021

Does not work for me: 404: Not Found

@bmaupin
Copy link
Author

bmaupin commented Dec 2, 2021

@moi90 I haven't personally used PDFEdit in a long time so the mirror links may be broken. If you find ones that work let me know and I'll udpate the script. Thanks!

@IgnacioRubioScola
Copy link

I found the version Qt5 version (64bit only):
http://sft.if.usp.br/proprietary/master-pdf-editor-4.3.89_qt5.amd64.deb

@bmaupin
Copy link
Author

bmaupin commented Feb 28, 2023

The package links have been broken for a long time. Updating them doesn't really work because the packages are too old to work in modern Ubuntu, so I updated the instructions to use PDFEdit in a container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment