Installing the Interactive Deep Colorization application in Linux

There are plenty of articles and videos on the Web regarding colourising old black and white photographs. Some of the resulting colourised photographs look amazing. Several Web sites offer free or commercial automated colourisation of B&W photographs using AI (artificial intelligence) techniques. The free-use sites watermark the result or limit the size of the original image. Some of the resulting colourised images are reasonable, others not so good.

Last year I scanned some 35 mm slides which are over 60 years old. The chemicals in some had degraded so much that the images are tinted red (‘redscale’ rather than ‘greyscale’!), too much to be able to fix using the GIMP. Out of curiosity I tried processing one of the scanned slides using some of the free online B&W photograph automated colourisers. The results in some cases were promising, alhough they would still require a lot of manual adjustment.

Scan of original 35 mm slide about 60 years old

Scan of original 35 mm slide about 60 years old

The image after processing using one of the free online B&W colouriser Websites

The image after processing using one of the free online B&W colouriser Websites

A few years ago Richard Zhang and colleagues at the University of California, Berkeley wrote software that uses similar AI techniques to colourise photographs but allows the user to manually influence the colourisation — see the Smithsonian Magazine article New App Makes It Easier to Colorize Old Photos for further information and a link to the GitHub repository of Jun-Yan Zhu with the team’s open-source software, written in Python. Zhang went on to join Adobe, and the software is now incorporated in Adobe PhotoShop Elements.

All my machines run Linux, and I wanted to try to install the open-source application from Jun-Yan Zhu’s GitHub repository. However, the Python code uses Qt4 but all my Linux installations use Qt5. Jun-Yan Zhu created a GitHub branch for the Python code to be modified for Qt5 but, to date, that branch still contains only Python code using Qt4:

https://github.com/junyanz/interactive-deep-colorization/tree/qt5

However, another GitHub user named Vishwaesh Rajiv cloned the code and ported it to Qt5 for use in a Docker container:

https://github.com/vwrj/interactive-deep-colorization

I decided to have a go at getting the application to work in Lubuntu 20.10 on my family’s desktop machine. Below are the results of my efforts, which unfortunately stalled because the machine only has 4 GB of RAM (the application apparently requires a lot of memory).

The installation instructions in the README.md file in both users’ repositories apply to the version using Qt4. Below is what I had to do to install the Qt5 version of the application from Vishwaesh Rajiv’s GitHub repository. Qt5 and PyQt5 are already installed in Lubuntu 20.10, so these are not included in the steps below (read Jun-Yan Zhu’s GitHub page for details). My family’s desktop machine does not have an NVIDIA GPU (it has an Intel IGP) so I used ‘CPU mode’ (see the README.md file for details).

user $ wget https://github.com/vwrj/interactive-deep-colorization/archive/master.zip
user $ unzip master.zip
user $ cp -r -p interactive-deep-colorization-master ideepcolor
user $ cd ideepcolor
user $ cp docker/ideepcolor_docker.py ideepcolor.py
user $ cp -r docker/ui_PyQt5/* ui/
user $ cp -r docker/data/* data/
user $ nano ideepcolor.py # Change the line 'from ui_PyQt5 import gui_design' to 'from ui import gui_design'
user $ bash ./models/fetch_models.sh
user $ sudo apt update
user $ sudo apt install caffe python3-caffe
user $ sudo apt install python3-opencv python3-sklearn python3-skimage
user $ sudo apt install python3-qdarkstyle
user $ sudo apt install python3-opencv

I used the following command in ~/ideepcolor/ to launch the application:

user $ python3 ideepcolor.py --cpu_mode --backend caffe --image_file test_imgs/parrot.jpg

From the output displayed in the terminal window the application seems to launch correctly:

[...]
Setting ab cluster centers in layer: pred_ab
Setting upsampling layer kernel: pred_313_us
b'test_imgs/parrot.jpg'
scale = 2.000000

but after a minute or two the memory used increases significantly (as seen in htop), no GUI is displayed and the terminal displays ‘Killed‘:

[...]
Setting ab cluster centers in layer: pred_ab
Setting upsampling layer kernel: pred_313_us
b'test_imgs/parrot.jpg'
scale = 2.000000
Killed

I could be wrong, but I assume the reason the application does not continue is because of insufficient RAM. When I get time I will try to install the various packages in Gentoo Linux on my main laptop with 16 GB RAM, to see if I can get it to work. If you are using a Linux installation that has Qt5 installed and your machine has plenty of RAM, you might be interested to try and install the Interactive Deep Colorization software to see if you can get it to work. If you do, please comment below.

Migrating to libglvnd in Gentoo Linux on a laptop with NVIDIA Optimus

In a 2015 post I described how I configured my Gentoo Linux installation to switch between the closed-source NVIDIA driver and the open-source Intel driver on a Clevo W230SS laptop that has NVIDIA Optimus hardware (NVIDIA GeForce GTX 860M GPU plus Intel HD 4600 IGP). I did not want to use Bumblebee, preferring to use only the NVIDIA driver or only the Intel driver, switching between them by running a Bash script then logging out of KDE Plasma and back in again. Basically, the scheme a) swapped the xorg.conf file depending on which driver I wanted to use, and b) used the eselect opengl command to select the applicable OpenGL library. The latest versions of the files in my scheme are listed below if you’re interested (I use LightDM instead of KDM these days, as KDM is no more), otherwise just skip to the section after, titled ‘Migrating to libglvnd’.

Previous scheme using eselect opengl

~/Desktop/Select_NVIDIA_GPU.desktop

[Desktop Entry]
Comment[en_GB]=Run a script to configure your installation to use the NVIDIA GeForce GTX 860M GPU when you restart X Windows
Comment=Run a script to configure your installation to use the NVIDIA GeForce GTX 860M GPU when you restart X Windows
Exec=konsole -e sh /home/fitzcarraldo/nvidia.sh
GenericName[en_GB]=Configure your installation to use the NVIDIA GeForce GTX 860M GPU
GenericName=Configure your installation to use the NVIDIA GeForce GTX 860M GPU
Icon=/home/fitzcarraldo/Pictures/Icons/nvidia_icon.png
MimeType=
Name[en_GB]=NVIDIA GPU
Name=NVIDIA GPU
Path=
StartupNotify=true
Terminal=false
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=fitzcarraldo

~/nvidia.sh

#!/bin/bash
echo
echo "Your installation is currently configured to use the following graphics processor:"
echo
GPU=`eselect opengl list | grep \* | awk '{ print $2 }'`
if [ "$GPU" = "nvidia" ]; then
  echo "NVIDIA GeForce GTX 860M"
  echo
  echo "You do not need to do anything. Please close this window."
elif [ "$GPU" = "xorg-x11" ]; then
  echo "Intel HD 4600 Integrated Graphics Processor"
  echo
  echo "This script will configure your installation to use the NVIDIA GeForce GTX 860M GPU all the time."
  echo
  echo "Enter your own password."
  echo
  sudo eselect opengl set nvidia
# See separate configuration of LightDM for NVIDIA GPU and Intel HD Graphics.
  sudo cp /etc/X11/xorg.conf.nvidia /etc/X11/xorg.conf
  echo
  echo "Now you should logout to restart X Windows."
fi
echo
echo -n "Press ENTER to end: "
read ACKNOWLEDGE

/etc/X11/xorg.conf.nvidia

Section "ServerLayout"
    Identifier     "Layout0"
    Screen      1  "nvidia" 0 0
    Inactive       "intel"
EndSection

Section "Monitor"
    Identifier     "Monitor0"
    Option         "DPMS"
    Option         "DPI" "96 x 96"
EndSection

Section "Device"
    Identifier     "nvidia"
    Driver         "nvidia"
    BusID          "PCI:1:0:0"
EndSection

Section "Device"
    Identifier     "intel"
    Driver         "modesetting"
    BusID          "PCI:0:2:0"
EndSection

Section "Screen"
    Identifier     "nvidia"
    Device         "nvidia"
    Monitor        "Monitor0"
    DefaultDepth    24
    Option         "UseDisplayDevice" "none"
    SubSection     "Display"
        Depth       24
        Virtual     1920 1080
    EndSubSection
EndSection

Section "Screen"
    Identifier     "intel"
    Device         "intel"
    Monitor        "Monitor0"
EndSection

~/Desktop/Select_Intel_HD_Graphics.desktop

[Desktop Entry]
Comment[en_GB]=Run a script to configure your installation to use Intel Integrated Graphics when you restart X Windows
Comment=Run a script to configure your installation to use Intel Integrated Graphics when you restart X Windows
Exec=konsole -e sh /home/fitzcarraldo/intel.sh
GenericName[en_GB]=Configure your installation to use Intel HD Graphics
GenericName=Configure your installation to use Intel HD Graphics
Icon=/home/fitzcarraldo/Pictures/Icons/intel-hd-icon.png
MimeType=
Name[en_GB]=Intel HD Graphics
Name=Intel HD Graphics
Path=
StartupNotify=true
Terminal=false
TerminalOptions=\s--noclose
Type=Application
X-DBUS-ServiceName=
X-DBUS-StartupType=none
X-KDE-SubstituteUID=false
X-KDE-Username=fitzcarraldo

~/intel.sh

#!/bin/bash
echo
echo "Your installation is currently configured to use the following graphics processor:"
echo
GPU=`eselect opengl list | grep \* | awk '{ print $2 }'`
if [ "$GPU" = "xorg-x11" ]; then
  echo "Intel HD 4600 Integrated Graphics Processor"
  echo
  echo "You do not need to do anything. Please close this window."
elif [ "$GPU" = "nvidia" ]; then
  echo "NVIDIA GeForce GTX 860M"
  echo
  echo "This script will configure your installation to use the"
  echo "Intel HD 4600 Integrated Graphics Controller all the time."
  echo
  echo "Enter your own password."
  echo
  sudo eselect opengl set xorg-x11
# See separate configuration of LightDM for Intel HD Graphics and NVIDIA GPU.
  sudo cp /etc/X11/xorg.conf.intel /etc/X11/xorg.conf
  echo
  echo "Now you should logout to restart X Windows."
fi
echo
echo -n "Press ENTER to end: "
read ACKNOWLEDGE

/etc/X11/xorg.conf.intel

Section "Device" 
   Identifier  "Intel Graphics" 
   Driver      "intel" 
   Option      "AccelMethod" "sna" 
   Option      "TearFree" "true" 
EndSection

/etc/X11/xorg.conf.d/20-opengl.conf

Section "Files"
        ModulePath "/usr/lib/xorg/modules"
        ModulePath "/usr/lib64/xorg/modules"
EndSection

/etc/X11/Sessions/plasma (used by LightDM)

#!/bin/bash
#
# Make sure the following is in /etc/lightdm/lightdm.conf
# display-setup-script=/etc/X11/Sessions/plasma
#
GPU=`eselect opengl list | grep \* | awk '{ print $2 }'`
if [ "$GPU" = "nvidia" ]; then
    xrandr --setprovideroutputsource modesetting NVIDIA-0
    xrandr --auto
fi

Migrating to libglvnd

Well, the above scheme worked fine… until the recent decision by the Gentoo Linux developers to drop the app-eselect/eselect-opengl ebuild and switch the x11-base/xorg-server, media-libs/mesa and x11-drivers/nvidia-drivers to using the libglvnd library:

This package is masked and could be removed soon!
The mask comment indicates that this package is scheduled for removal from our package repository.
Please review the mask information below for more details.

Replaced by media-libs/libglvnd. Masked for removal in 30 days. Bug #728286

Affected packages	app-eselect/eselect-opengl

Author/Date		Matt Turner  (2020-08-11 00:00:00 +0000 UTC)

Without the eselect opengl command, my scripts were scuppered. So I decided to bite the bullet and switch to using libglvnd. It turned out not to be difficult, and I took the following steps to migrate:

  1. Deleted the file /etc/X11/xorg.conf
  2. Created the file /etc/X11/xorg.conf.d/01-nvidia-offload.conf containing the following:
    Section "ServerLayout"
        Identifier "layout"
        Option "AllowNVIDIAGPUScreens"
    EndSection
    
  3. Performed the usual ‘emerge -uvDN @world‘ to update and upgrade the relevant packages, which automatically unmerged app-eselect/eselect-opengl

If I had run into trouble with the installed app-eselect/eselect-opengl blocking the upgrade, I could have worked around that by doing the following:

root # emerge -C eselect-opengl
root # emerge -1v nvidia-drivers mesa xorg-server xorg-drivers

I removed all references to the libglvnd USE flag from /etc/portage/make.conf, and the only place libglvnd is declared explicitly now is in the file /etc/portage/package.use/world because I have a multilib installation:

root # grep libglvnd /etc/portage/package.*/*
/etc/portage/package.use/world:>=media-libs/libglvnd-1.3.1 abi_x86_32

The status of the applicable packages in my installation is now as follows:

root # eix -I nvidia-drivers
[I] x11-drivers/nvidia-drivers
     Available versions:  [M]340.108-r1(0/340)^mtd ~390.132-r4(0/390)^mtd 390.138-r1(0/390)^mtd 435.21-r6(0/435)^mtd 440.100-r2(0/440)^mtd 450.57-r1(0/450)^mtd {+X compat (+)driver gtk3 +kms +libglvnd multilib static-libs +tools uvm wayland ABI_MIPS="n32 n64 o32" ABI_RISCV="lp64 lp64d" ABI_S390="32 64" ABI_X86="32 64 x32" KERNEL="FreeBSD linux"}
     Installed versions:  450.57-r1(0/450)^mtd(22:04:56 14/08/20)(X driver kms libglvnd multilib tools wayland -compat -gtk3 -static-libs -uvm ABI_MIPS="-n32 -n64 -o32" ABI_RISCV="-lp64 -lp64d" ABI_S390="-32 -64" ABI_X86="32 64 -x32" KERNEL="linux -FreeBSD")
     Homepage:            https://www.nvidia.com/Download/Find.aspx
     Description:         NVIDIA Accelerated Graphics Driver

root # eix -I mesa
[I] media-libs/mesa
     Available versions:  20.0.8^t ~20.1.4^t ~20.1.5^t ~20.2.0_rc1^t ~20.2.0_rc2^t **9999*l^t {+X +classic d3d9 debug +dri3 +egl +gallium +gbm gles1 +gles2 +libglvnd +llvm lm-sensors opencl osmesa selinux test unwind vaapi valgrind vdpau vulkan vulkan-overlay wayland xa xvmc zink +zstd ABI_MIPS="n32 n64 o32" ABI_RISCV="lp64 lp64d" ABI_S390="32 64" ABI_X86="32 64 x32" KERNEL="linux" VIDEO_CARDS="freedreno i915 i965 intel iris lima nouveau panfrost r100 r200 r300 r600 radeon radeonsi v3d vc4 virgl vivante vmware"}
     Installed versions:  20.0.8^t(22:03:42 14/08/20)(X classic dri3 egl gallium gbm gles2 libglvnd llvm wayland zstd -d3d9 -debug -gles1 -lm-sensors -opencl -osmesa -selinux -test -unwind -vaapi -valgrind -vdpau -vulkan -vulkan-overlay -xa -xvmc ABI_MIPS="-n32 -n64 -o32" ABI_RISCV="-lp64 -lp64d" ABI_S390="-32 -64" ABI_X86="32 64 -x32" KERNEL="linux" VIDEO_CARDS="i965 intel -freedreno -i915 -iris -lima -nouveau -panfrost -r100 -r200 -r300 -r600 -radeon -radeonsi -vc4 -virgl -vivante -vmware")
     Homepage:            https://www.mesa3d.org/ https://mesa.freedesktop.org/
     Description:         OpenGL-like graphic library for Linux

[I] x11-apps/mesa-progs
     Available versions:  8.4.0 **9999*l {egl gles2}
     Installed versions:  8.4.0(13:53:51 02/05/19)(-egl -gles2)
     Homepage:            https://www.mesa3d.org/ https://mesa.freedesktop.org/ https://gitlab.freedesktop.org/mesa/demos
     Description:         Mesa's OpenGL utility and demo programs (glxgears and glxinfo)

Found 2 matches
root # eix -I xorg-server
[I] x11-base/xorg-server
     Available versions:  1.20.8-r1(0/1.20.8) **9999(0/9999)*l {debug dmx doc +elogind ipv6 kdrive +libglvnd libressl minimal selinux static-libs suid systemd +udev unwind wayland xcsecurity xephyr xnest xorg xvfb}
     Installed versions:  1.20.8-r1(0/1.20.8)(22:07:21 14/08/20)(elogind ipv6 libglvnd udev wayland xorg -debug -dmx -doc -kdrive -libressl -minimal -selinux -static-libs -suid -systemd -unwind -xcsecurity -xephyr -xnest -xvfb)
     Homepage:            https://www.x.org/wiki/ https://gitlab.freedesktop.org/xorg/xserver/xorg-server
     Description:         X.Org X servers

root # eix -I xorg-drivers
[I] x11-base/xorg-drivers
     Available versions:  1.20-r2 **9999*l {INPUT_DEVICES="elographics evdev joystick libinput synaptics vmmouse void wacom" VIDEO_CARDS="amdgpu ast dummy fbdev freedreno geode glint i915 i965 intel mga nouveau nv nvidia omap qxl r128 radeon radeonsi siliconmotion tegra vc4 vesa via virtualbox vmware"}
     Installed versions:  1.20-r2(22:05:41 14/08/20)(INPUT_DEVICES="evdev synaptics -elographics -joystick -libinput -vmmouse -void -wacom" VIDEO_CARDS="i965 intel nvidia -amdgpu -ast -dummy -fbdev -freedreno -geode -glint -i915 -mga -nouveau -nv -omap -qxl -r128 -radeon -radeonsi -siliconmotion -tegra -vc4 -vesa -via -virtualbox -vmware")
     Homepage:            https://wiki.gentoo.org/wiki/No_homepage
     Description:         Meta package containing deps on all xorg drivers

I can now delete the line display-setup-script=/etc/X11/Sessions/plasma in /etc/lightdm/lightdm.conf, and delete the script /etc/X11/Sessions/plasma, as the script no longer works and the xrandr commands in it are no longer necessary in any case. The files and scripts Select_NVIDIA_GPU.desktop, nvidia.sh, xorg.conf.nvidia, Select_Intel_HD_Graphics.desktop, intel.sh and xorg.conf.intel are also redundant now and can be deleted.

After rebooting, the LightDM login screen appears as usual and I can login to the Desktop Environment. I can connect an external monitor to the laptop via either VGA cable or HDMI cable and both methods work, and I can switch between the laptop monitor and the external monitor using KDE Plasma’s ‘System Settings’ > ‘Display Configuration’, so everything appears to be working correctly.

The command xrandr --listproviders (add ‘--verbose‘ to provide more information) lists both the NVIDIA and Intel video devices, so I assume everything is working correctly:

user $ xrandr --listproviders
Providers: number : 2
Provider 0: id: 0x47 cap: 0xb, Source Output, Sink Output, Sink Offload crtcs: 4 outputs: 4 associated providers: 0 name:Intel
Provider 1: id: 0x203 cap: 0x0 crtcs: 0 outputs: 0 associated providers: 0 name:NVIDIA-G0

It appears that the default is to use the Intel IGP:

user $ glxinfo | grep -E 'OpenGL (vendor|renderer)'
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 4600 (HSW GT2)
user $ __NV_PRIME_RENDER_OFFLOAD_PROVIDER=Intel __GLX_VENDOR_LIBRARY_NAME=mesa glxinfo  | grep -E 'OpenGL (vendor|renderer)'
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) HD Graphics 4600 (HSW GT2)

unless I use environment variables explicitly to specify that the NVIDIA GPU be used for a specific application:

user $ __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 __GLX_VENDOR_LIBRARY_NAME=nvidia glxinfo  | grep -E 'OpenGL (vendor|renderer)'
OpenGL vendor string: NVIDIA Corporation
OpenGL renderer string: GeForce GTX 860M/PCIe/SSE2

Performance seems reasonable:

user $ __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 __GLX_VENDOR_LIBRARY_NAME=nvidia __GL_SYNC_TO_VBLANK=0 glxgears
27197 frames in 5.0 seconds = 5439.292 FPS
27332 frames in 5.0 seconds = 5466.274 FPS
27857 frames in 5.0 seconds = 5571.184 FPS
27553 frames in 5.0 seconds = 5510.447 FPS
27128 frames in 5.0 seconds = 5425.556 FPS
^C

To run a program such as LibreCAD using the NVIDIA GPU I can do the following:

user $ __NV_PRIME_RENDER_OFFLOAD_PROVIDER=NVIDIA-G0 __GLX_VENDOR_LIBRARY_NAME=nvidia librecad

I need to play around more to understand how to use nvidia-drivers and libglvnd with the NVIDIA Optimus hardware in this laptop, but at least I have managed to migrate from app-eselect/eselect-opengl to media-libs/libglvnd before the former is dropped from the Portage tree in the near future.

Paul Gideon Dann’s patchset for Poppler to enable Okular (Qt5) to use Cairo rather than Splash to render PDF files

If you view the same PDF file in Okular (KDE) and Evince (GNOME), you may notice that fonts and lines are rendered better in Evince. Both applications use Poppler to render text and graphics in PDF files, but Poppler uses a different rendering backend in the two applications. For Evince Poppler uses the Cairo library, whereas for Okular Poppler uses Splash, a backend inherited from Poppler’s predecessor Xpdf (still in development). Unfortunately for KDE users, Cairo often does a better job than Splash. However, independent software engineer Paul Gideon Dann came to the rescue by producing the patchset poppler-cairo-backend to modify Poppler in order to make it use the Cairo library instead of Splash when Poppler is used by Okular. To quote the README file for Paul’s patchset:

Purpose of this Patchset

Currently, the default backend for the Qt5 wrapper (used by Okular) is Splash. Unfortunately, Splash does not support subpixel rendering of fonts, so those of us using KDE are stuck with somewhat ugly-looking fonts. This patchset adds support for the Cairo backend to the Qt5 wrapper. It also forces subpixel rendering in the Cairo backend. The upshot of this is that we get beautiful fonts in Okular.

The README focuses on fonts, but in fact the rendering of lines in graphics in PDF files can also be improved by the application of the patchset.

Apparently the Poppler maintainer feels that the introduction of a dependency on Cairo to the Qt5 wrapper (even an optional dependency) in Poppler would be controversial, and he is not willing to merge the patchset. For Okular users who already have Cairo installed (e.g. for Firefox, Inkscape, Scribus and so on), and who are noticing inadequate rendering of some PDF files, Paul’s patchset is worth trying.

In Gentoo Linux, which is a source code-based distribution, it is very easy to apply the patchset. For example, I did the following to apply the patchset for Poppler 0.80.0 in a ~amd64 (Testing Branch) installation:

1. Created a package-specific and version-specific directory to hold the patchset:

root # mkdir -p /etc/portage/patches/app-text/poppler-0.80.0

2. Downloaded the patchset for Poppler 0.80.0 from the following Web page:

https://github.com/giddie/poppler-cairo-backend/tree/76e607bcf010d6d9b8df5cb0f851ef9c91d4caf2

3. Copied the patchset to the directory created in Step 1:

root # cp /home/fitzcarraldo/Downloads/*.patch /etc/portage/patches/app-text/poppler-0.80.0/
root # ls -1 /etc/portage/patches/app-text/poppler-0.80.0
0001-Cairo-backend-added-to-Qt5-wrapper.patch
0002-Setting-default-Qt5-backend-to-Cairo.patch
0003-Apply-subpixel-rendering-in-Cairo-Backend.patch

4. Checked first that the patchset could be applied successfully before actually using it:

root # cd /usr/portage/app-text/poppler
root # ebuild poppler-0.80.0.ebuild clean prepare
 * poppler-0.80.0.tar.xz BLAKE2B SHA512 size ;-) ...                                     [ ok ]
 * checking ebuild checksums ;-) ...                                                     [ ok ]
 * checking auxfile checksums ;-) ...                                                    [ ok ]
 * checking miscfile checksums ;-) ...                                                   [ ok ]
>>> Unpacking source...
>>> Unpacking poppler-0.80.0.tar.xz to /var/tmp/portage/app-text/poppler-0.80.0/work
>>> Source unpacked in /var/tmp/portage/app-text/poppler-0.80.0/work
>>> Preparing source in /var/tmp/portage/app-text/poppler-0.80.0/work/poppler-0.80.0 ...
 * Applying poppler-0.60.1-qt5-dependencies.patch ...                                    [ ok ]
 * Applying poppler-0.28.1-fix-multilib-configuration.patch ...                          [ ok ]
 * Applying poppler-0.78.0-respect-cflags.patch ...                                      [ ok ]
 * Applying poppler-0.61.0-respect-cflags.patch ...                                      [ ok ]
 * Applying poppler-0.57.0-disable-internal-jpx.patch ...                                [ ok ]
 * Applying 0001-Cairo-backend-added-to-Qt5-wrapper.patch ...                            [ ok ]
 * Applying 0002-Setting-default-Qt5-backend-to-Cairo.patch ...                          [ ok ]
 * Applying 0003-Apply-subpixel-rendering-in-Cairo-Backend.patch ...                     [ ok ]
 * User patches applied.
>>> Source prepared.

5. Re-merged Poppler to apply the patchset to the Poppler source code and rebuild the patched package:

root # emerge -1v poppler

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] app-text/poppler-0.80.0:0/90::gentoo  USE="cairo cjk cxx introspection jpeg jpeg2k lcms png qt5 tiff utils -curl -debug -doc -nss" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

>>> Verifying ebuild manifests
>>> Emerging (1 of 1) app-text/poppler-0.80.0::gentoo
>>> Installing (1 of 1) app-text/poppler-0.80.0::gentoo
>>> Jobs: 1 of 1 complete                           Load avg: 1.06, 1.11, 0.95
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.

6. Re-merged Okular so that it uses the patched Poppler dependency:

root # emerge -1v okular

These are the packages that would be merged, in order:

Calculating dependencies... done!
[ebuild   R    ] kde-apps/okular-19.08.1:5::gentoo  USE="chm crypt djvu image-backend pdf postscript tiff -debug -epub -handbook -markdown -mobi -mobile -plucker -share -speech -test" 0 KiB

Total: 1 package (1 reinstall), Size of downloads: 0 KiB

>>> Verifying ebuild manifests
>>> Emerging (1 of 1) kde-apps/okular-19.08.1::gentoo
>>> Installing (1 of 1) kde-apps/okular-19.08.1::gentoo
>>> Jobs: 1 of 1 complete                           Load avg: 1.17, 1.13, 1.04
>>> Auto-cleaning packages...

>>> No outdated packages were found on your system.

 * GNU info directory index is up-to-date.

My thanks go to Paul for taking the time to produce the patchset.

How to create missing favicons for your bookmarks in Firefox Quantum for Linux

Prior to the advent of Firefox Quantum, several add-ons were available that enabled you to replace the favicons of bookmarks in Firefox, or to create custom favicons for bookmarks lacking a favicon. One of my favourite such add-ons was Favicon Picker 3. However, Firefox Quantum currently lacks an add-on that would enable you to insert a favicon of your choice for bookmarks without one. This has annoyed me for some time, as my bookmarks menu in Firefox includes several Web sites without favicons. Today I found a 2013 post ‘How to change Firefox bookmark icons (favicons) without extensions or addons!‘ for Windows predating Firefox Quantum. I have applied a similar procedure for Firefox Quantum in Linux in order to add a custom favicon to each bookmark in my bookmarks menu that did not already have a favicon. The procedure I used is given below.

1. Launch Firefox and enter ‘about:support’ (without the quotes) in the address bar.

2. Click on ‘Profile Directory’ > ‘Open Directory’ (which, in my case, is the directory /home/fitzcarraldo/.mozilla/firefox/l7nt0jx2.default).

3. Create the sub-directory ‘chrome‘.

4. Open the new directory’s folder.

5. Create the file ‘userChrome.css‘ in the new directory.

6. Open the file userChrome.css with a text editor and paste the following CSS code into it:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

.bookmark-item[label="<bookmark name>"] image {
    width:0!important;
    height:0!important;
    padding: 0 0 16px 16px !important;
    background:url(<base64 string>)!important; 
}

7. Make the following changes to the above code:

7.1 Replace ‘<bookmark name>’ with the name of the bookmark as it appears in the bookmarks menu. You must supply a name, even if you do not want a name to appear.

7.2 Replace ‘<base64 string>’ with the base64-encoded string of the desired favicon, which you can obtain by uploading the 16×16 pixel image file to a website such as https://www.base64-image.de/.

Example

Below are the steps I took to create a favicon for the bookmark for Hotmail I have in Firefox:

1. I used a search engine to find an image of the Microsoft ‘flag’ logo. The image happened to be a 200×200 pixels PNG file. I downloaded it to my home directory and named it ‘Microsoft.png‘.

2. I loaded the image file into the GIMP, scaled it to 16×16 pixels and exported it as Microsoft.png to overwrite the original downloaded file.

3. I viewed the Web page https://www.base64-image.de/ in a Web browser and clicked on the button ‘OR CLICK HERE’ to upload my image file Microsoft.png to that site. Then I clicked on the button ‘</> show code’, selected and copied the text displayed underneath ‘For use as CSS background:’ that looked like this:

url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAOVBMVEXxURv7vAmAzCgAre/////xTxf8wB8csfD7wCXyXjDyWyuHzzaJ0Dohs/DyWSj0Zz2Q00b8xDMxt/HxkgKEAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4goMEQsUc/RzwQAAAB5JREFUGNNjYIAAViYoYKCPACsUwAWYoYARCgZIAADfYwHMYVta3QAAAABJRU5ErkJggg==')

4. I created the directory ~/.mozilla/firefox/l7nt0jx2.default/chrome and the file userChrome.css containing the following:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

.bookmark-item[label="Hotmail"] image {
    width:0!important;
    height:0!important;
    padding: 0 0 16px 16px !important;
    background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAOVBMVEXxURv7vAmAzCgAre/////xTxf8wB8csfD7wCXyXjDyWyuHzzaJ0Dohs/DyWSj0Zz2Q00b8xDMxt/HxkgKEAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4goMEQsUc/RzwQAAAB5JREFUGNNjYIAAViYoYKCPACsUwAWYoYARCgZIAADfYwHMYVta3QAAAABJRU5ErkJggg==')!important; 
}

5. I restarted Firefox, and my custom favicon is now visible for the Hotmail entry in the Bookmarks Menu. I then deleted the file ~/Microsoft.png as it is no longer required.

6. I also wanted to create a custom favicon for another bookmark I have, the Web site of a Brazilian newspaper Correio Popular. As I was unable to find an image that would be suitable for a favicon, I created one myself (16×16 pixels) using the GIMP, and exported it as the file ‘~/Correio Popular.png‘.

7. I followed the same procedure to encode the image file as a Base64 image, and I added another entry to the file ~/.mozilla/firefox/l7nt0jx2.default/chrome/userChrome.css, which now contains the following:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul");

.bookmark-item[label="Hotmail"] image {
    width:0!important;
    height:0!important;
    padding: 0 0 16px 16px !important;
    background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAAOVBMVEXxURv7vAmAzCgAre/////xTxf8wB8csfD7wCXyXjDyWyuHzzaJ0Dohs/DyWSj0Zz2Q00b8xDMxt/HxkgKEAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4goMEQsUc/RzwQAAAB5JREFUGNNjYIAAViYoYKCPACsUwAWYoYARCgZIAADfYwHMYVta3QAAAABJRU5ErkJggg==')!important; 
}

.bookmark-item[label="Correio Popular"] image {
    width:0!important;
    height:0!important;
    padding: 0 0 16px 16px !important;
    background:url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAIAAACQkWg2AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4goMFzEqk7HMoQAAAQdJREFUKM/NkrGKg0AURd+EwSkMBPwLSxlI5dR+haSxFE0T7KxtghCwtfNH7FLZpkkXgvMDophwtzArYUMWUizsad7j8i7cC48BoE9Y0If8vYFPo+u6MAxXq9VyubxcLoyxsiz3+31VVUqp6/WqlIqiiIgIAADO+el0wje73W5a5oP1el0UBQACUBSF67p4ou97ALfbbTakaer7PoAFER2PR8dxnoMKIX5Er+taSvnoMI4j5/xdy+12ez6fpZRxHD86ZFnmed7vkWYIwDAMRKS1ntUkSQDc7/dXAyciwzC01kEQ2LZtmmbbtk3TENHhcBBC5Hm+2Wwsy5oSsne/BIAx9qqz//d8XzCj1kv+0nVJAAAAAElFTkSuQmCC')!important; 
}

8. For any other bookmarks that do not have a favicon, I will just repeat the procedure to add further entries to the file ~/.mozilla/firefox/l7nt0jx2.default/chrome/userChrome.css. It is not as easy as using an add-on, but, until someone creates one, the process described above at least allows me to fill those annoying favicon gaps in the Firefox bookmark menus on my machines.

Gentoo Linux: A work-around to be able to Resume from Suspend to RAM when using the NVIDIA closed-source driver

My Clevo W230SS laptop has NVIDIA Optimus graphics hardware (NVIDIA GPU plus Intel IGP). I do not use Bumblebee, preferring to switch between the Intel video driver and the NVIDIA closed-source driver myself (see Switching between Intel and NVIDIA graphics processors on a laptop with NVIDIA Optimus hardware running Gentoo Linux). The laptop can suspend to RAM and resume perfectly when using the Intel video driver (but see Stopping my laptop spontaneously resuming immediately after Suspend to RAM, which is applicable whatever the GPU or IGP).

In order to be able to resume properly from Suspend-to-RAM when using the NVIDIA driver, the laptop needs to disable compositing before suspending, then re-enable compositing after resuming. For how I achieve that, see under Problem 2 in the third link above. If this is not done, the graphics on the Desktop are corrupted after resuming.

However, recently when using the NVIDIA driver and KDE Plasma 5 (I am currently using nvidia-drivers-387.22 and plasma-meta-5.11.5), when resuming from suspension the monitor would briefly display the LightDM wallpaper (I use different wallpapers for the display manager and the lock screen, so I know it was not the KDE lock screen) followed by a blank screen with a mouse pointer (which I could move normally). More recently, in between displaying the display manager’s wallpaper and the blank screen, the monitor would briefly display an earlier image of the Desktop just before the laptop suspended.

Now, I could simply leave the laptop configured to use the Intel driver. However, sometimes I need to use a CAD application and the performance is better when using the NVIDIA GPU.

There are umpteen posts on the Web about this problem, and the root cause seems to be the closed-source NVIDIA driver. I have seen the KDE lock screen mentioned in some posts as the culprit, so I disabled the lock screen (‘System Settings’ > ‘Desktop Behaviour’ > ‘Screen Locking’) but that did not solve the problem.

I put up with this for several weeks in the hope that the next release of the NVIDIA driver would fix the problem. If I suspended to RAM while the laptop was using the NVIDIA driver, I was able to resume and get to a working Desktop – albeit without the open windows and applications that had been running before suspending – by pressing Ctrl+Alt+F1 to get to TTY1, logging in as the root user and entering the command ‘/etc/init.d/xdm restart‘. However, the final straw was in a meeting a couple of weeks ago when I wanted to resume the laptop and show a worksheet to someone. The laptop monitor of course displayed a blank screen with a mouse pointer, and it took me a couple of minutes to restart the display manager, login to KDE Plasma 5 and open the spreadsheet again. So this week I decided to look into the problem to see if I could at least find a work-around that would enable the laptop to resume without needing to restart X Windows and login to Plasma 5 each time.

I created a Bash script in /etc/pm/sleep.d/ to unload the NVIDIA modules before suspending to RAM and to re-load them when resuming, but that did not solve the problem either.

I switched the rendering background from OpenGL 2.0 to OpenGL 3.1 (‘System Settings’ > ‘Display and Monitor’ > ‘Compositor’), but that did not work either. I switched the rendering backend to XRender, and that did enable the laptop to resume from suspend successfully with the NVIDIA driver, but I do not want to use that work-around. Firstly, with software rendering there is a performance hit, and, secondly, there was no KDE Desktop Cube when using XRender instead of OpenGL. I use the Desktop Cube when working, as I often have a lot of windows open on each virtual desktop (cube side), and I find it easier to use the cube than a flat UI.

Eventually I found that, after resuming, if I pressed Ctrl+Alt+F1 to get to a virtual console, logged into my user account, entered the command ‘DISPLAY=:0 /usr/bin/kwin_x11 --resume‘ and then pressed Ctrl+Alt+F7 to get back to TTY7, my Desktop would appear on TTY7. Even so, I noticed on TTY1 that the following error messages were displayed when I ran that command:

kwin_core: OpenGL 2 compositing setup failed
kwin_core: Failed to initialize compositing, compositing disabled

Anyway, the Plasma 5 Desktop was displayed on TTY7, and with the windows that were open when I suspended the laptop, so restarting KWin would at least be a viable work-around until NVIDIA fix their video driver.

I incoporated the command in my script /etc/pm/sleep.d/02-toggle-compositing like so:

#!/bin/sh
#
# Turn off compositing on hibernate or suspend
# Turn on compositing on thaw or resume

username=fitzcarraldo
userhome=/home/$username
export XAUTHORITY="$userhome/.Xauthority"
export DISPLAY=":0"

case "$1" in
     suspend|hibernate)
          su $username -c "qdbus org.kde.KWin /Compositor suspend" &
     ;;
     resume|thaw)
          su $username -c "qdbus org.kde.KWin /Compositor resume" &
          su $username -c "/usr/bin/kwin_x11 --replace" &
     ;;
     *)
          exit $NA
     ;;
esac

It is an ugly hack, but at least now the laptop can resume properly from Suspend-to-RAM while the NVIDIA driver is being used.

Perhaps Linus Torvalds was correct. I will try to avoid NVIDIA hardware when I replace my current laptop.

How to capture a screenshot of the SDDM greeter screen

In my previous post I explained how to capture a screenshot of the LightDM greeter screen. The procedure is essentially the same for the SDDM greeter screen; only the Bash script differs slightly. The procedure is given below.

  1. If they are not already installed, install the packages x11-apps/xwd and media-gfx/imagemagick.

  2. Create the Bash script ~/sddm-greeter-capture.sh containing the following:
    TMPXAUTHORITY=$(ls /var/run/sddm/*)
    sleep 30
    DISPLAY=:0 XAUTHORITY=/var/run/sddm/$TMPXAUTHORITY xwd -root > /tmp/greeter.xwd
    convert /tmp/greeter.xwd /home/fitzcarraldo/greeter.png
    

    Make sure you make it executable:

    user $ chmod +x sddm-greeter-capture.sh

  3. Log out of the Desktop Environment so that the SDDM greeter screen is displayed.

  4. Press Ctrl+Alt+F2 to switch to VT2.

  5. Log in to you user account and enter the following command (do not wait for it to complete):

    user $ sudo /home/fitzcarraldo/sddm-greeter-capture.sh

  6. As soon as you have pressed Enter for the above command, press Ctrl+Alt+F7 to switch back to VT7.

  7. Wait for at least 30 seconds to be sure the Bash script has made a snapshot of the SDDM greeter screen, then log in.

  8. You should now find the file ~/greeter.png containing a snapshot of your SDDM greeter screen.

If you install media-libs/netpbm instead of (or as well as) media-gfx/imagemagick then you can use a different command to convert in the Bash script:

TMPXAUTHORITY=$(ls /var/run/sddm/*)
sleep 30
#DISPLAY=:0 XAUTHORITY=/var/run/sddm/$TMPXAUTHORITY xwd -root | xwdtopnm | pnmtopng > /home/fitzcarraldo/greeter.png

The resulting PNG image looks equally good to my eyes.

How to capture a screenshot of the LightDM greeter screen

  1. If they are not already installed, install the packages x11-apps/xwd and media-gfx/imagemagick.

  2. Create the Bash script ~/lightdm-greeter-capture.sh containing the following:
    #!/bin/bash
    sleep 30
    DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/$DISPLAY xwd -root > /tmp/greeter.xwd
    convert /tmp/greeter.xwd /home/fitzcarraldo/greeter.png
    

    Make sure you make it executable:

    user $ chmod +x lightdm-greeter-capture.sh

  3. Log out of the Desktop Environment so that the LightDM greeter screen is displayed.

  4. Press Ctrl+Alt+F2 to switch to VT2.

  5. Log in to you user account and enter the following command (do not wait for it to complete):

    user $ sudo /home/fitzcarraldo/lightdm-greeter-capture.sh

  6. As soon as you have pressed Enter for the above command, press Ctrl+Alt+F7 to switch back to VT7.

  7. Wait for at least 30 seconds to be sure the Bash script has made a snapshot of the LightDM greeter screen, then log in.

  8. You should now find the file ~/greeter.png containing a snapshot of your LightDM greeter screen.

If you install media-libs/netpbm instead of (or as well as) media-gfx/imagemagick then you can use a different command to convert in the Bash script:

#!/bin/bash
sleep 30
DISPLAY=:0 XAUTHORITY=/var/run/lightdm/root/$DISPLAY xwd -root | xwdtopnm | pnmtopng > /home/fitzcarraldo/greeter.png

The resulting PNG image looks equally good to my eyes.

A long overdue update to Google Earth for Linux

Google has finally released Version 7.1.7.2600 of Google Earth for Linux, fixing various crashes and the infamous empty Panoramio window. The last version of Google Earth for Linux that worked properly ‘out of the box’ in Gentoo Linux for me was 5.2.1.1588, and that was several years ago.

The current version of Google Earth in the Portage main tree is 7.1.4.1529. That version does not display Panoramio photos in Gentoo Linux (Stable Branch) on my Clevo W230SS laptop (NVIDIA Optimus), and Version 7.1.4.1529 crashes at launch more often than not. So I was keen to try the new version. Below are the steps I followed to install Version 7.1.7.2600 in the Portage local overlay on the laptop. If you don’t already have a local overlay, see the Gentoo Wiki article Overlay/Local overlay. Don’t forget to copy the files directory and its contents from /usr/portage/sci-geosciences/googleearth/ to /usr/local/portage/sci-geosciences/googleearth/ as well.

1. Download the file google-earth-stable_current_amd64.deb from the Google Earth Web site (Download the latest version of Google Earth for PC, Mac or Linux).

2. Edit the file /etc/portage/package.use/googleearth and add the line:

=sci-geosciences/googleearth-7.1.7.2600 -bundled-libs

3. Edit the file /etc/portage/package.unmask/googleearth and add the line:

=sci-geosciences/googleearth-7.1.7.2600

4. Edit the file /etc/portage/package.accept_keywords/googleearth and add the line:

=sci-geosciences/googleearth-7.1.7.2600 ~amd64

5. Copy the downloaded binary package to the distfiles directory and rename the package:

root # cp /home/fitzcarraldo/Downloads/google-earth-stable_current_amd64.deb /usr/portage/distfiles/GoogleEarthLinux-7.1.7.2600_amd64.deb

6. Create an ebuild for the new version and generate a manifest:

root # cd /usr/local/portage/sci-geosciences/googleearth/
root # cp /usr/portage/sci-geosciences/googleearth/googleearth-7.1.4.1529.ebuild googleearth-7.1.7.2600.ebuild
root # ebuild googleearth-7.1.7.2600.ebuild manifest

7. Install Google Earth 7.1.7.2600:

root # emerge =googleearth-7.1.7.2600

The package was installed without any trouble:

root # eix -I googleearth
[I] sci-geosciences/googleearth
     Available versions:  {M}(~)7.1.4.1529^m {M}(~)7.1.7.2600^m[1] {+bundled-libs}
     Installed versions:  7.1.7.2600^m[1](00:02:27 02/10/16)(-bundled-libs)
     Homepage:            https://earth.google.com/
     Description:         A 3D interface to the planet

[1] "local_overlay" /usr/local/portage

Google Earth for Linux 7.1.7.2600 launches quickly and without trouble on this laptop, and Panoramio photos are indeed now visible again (finally!). The only issue is one I also came across over a year ago after hacking an earlier version of Google Earth for Linux: If you click on a photo icon and the Panoramio window that opens displays several thumbnails, clicking on a thumbnail results in a white Panoramio window without any photo and thumbnails. Apparently this only happens in KDE. Anyway, the work-around is to right-click on the desired thumbnail and select ‘Open in New Window’.

Completing PDF forms and adding your signature without having to print the form

A recent post in the Gentoo Forums made me interested to find out what is actually achievable with fillable PDF forms in Gentoo Linux and Windows 10 without being required to purchase a software licence, be it for personal or professional use, in order to be able to complete PDF forms (including forms that have automatically-updating bar codes).

Designing PDF Forms

It is possible to create PDF forms with LibreOffice, although LibreOffice cannot create a form containing bar codes that get updated automatically with the information entered in fields on the form. In order to create PDF forms that contain automatically-updating bar codes it is necessary to purchase Adobe Acrobat DC or Adobe LiveCycle Designer, which are Windows-only applications. As forms usually have several fields, 2D bar code symbologies are used in order to be able to encode the amount of data in a practical way. See the Adobe demonstration video Capture electronic data from printed forms.

Using PDF Forms

However, the enquiry in the above-mentioned forum thread was not about designing PDF forms, it was about being able to complete existing PDF forms (including forms that have automatically-updating bar codes, and including being able to add a written signature to the form without printing it out):

Hi,

I need to sign pdfs, and sometimes fill out pdf forms which also need to be signed. At the moment I get them, print them, sign them and scan them back in to return to the sender. I’d like to simplify that.

I know that on Windows and Mac OS your adobe software can sign the pdf, but I don’t even know how that works exactly.

It would be really neat if there were an app which could handle all that.

Oh yeah, another thing. Some forms (all?) when you fill them out and print them have a bar of machine-readable gobbledygook on the page which lets the recipient of a printed pdf scan the data back in with 100% accuracy. That would be neat too.

Thanks.

Although I have sometimes added my signature to a PDF form before printing it out — more on that later — I had never come across PDF forms with automatically-updating bar codes, so my curiosity was piqued. I decided to investigate if free applications could be used to complete PDF forms (including those with automatically-updating bar codes) and add a written signature. My investigations were carried out in Linux and Windows 10, and my findings are given below. In summary, I discovered that I could do all these things in Linux as well as in Windows 10, although in Linux I had to resort to running a Windows application under WINE if a PDF form contained automatically-updating bar codes. I did not bother trying the GNOME document viewer Evince, as I could find no evidence on the Web of it having the capability of updating bar codes automatically, and I use KDE.

For my tests I used the following four PDF forms I found on the Web:

  1. acrobat8_barcodedforms.pdf, an October 2006 PDF article from Adobe containing three sample form fields and an associated automatically-updating bar code (PDF417 symbology).
  2. barcode_field.pdf, a February 2013 sample PDF form with three fields and three associated bar codes of different symbologies (PDF417, Data Matrix and QR Code).
  3. PdfFormExample.pdf, a June 2013 sample PDF form created using LibreOffice (and therefore not containing automatically-updating bar codes).
  4. sample_barcoded_demo.pdf, a December 2005 sample PDF form from Adobe with an automatically-updating bar code (PDF417 symbology).

1. Windows 10

1.1 Acrobat Reader DC

This is the ubiquitous ‘free’ closed-source application you can download from Adobe.

Below are screenshots of the four sample PDF forms opened in Acrobat Reader DC…

1.1.1 I could enter text in the three fields in acrobat8_barcodedforms.pdf, and the bar code was updated accordingly:

Acrobat Reader DC - acrobat8_barcodedforms.pdf

Acrobat Reader DC - acrobat8_barcodedforms.pdf

I used my smartphone’s Barcode Scanner app to read the bar code on the hard-copy form printed by Acrobat Reader DC:

Text1Text2Text3I am able to change the text in these fields of this form to see how 2D barcodes work.

1.1.2 I could enter text in the three fields in barcode_field.pdf, but the three bar codes were not visible:

Acrobat Reader DC - acrobat8_barcodedforms.pdf

Acrobat Reader DC - barcode_field.pdf

1.1.3 I could enter text in the fields in PdfFormExample.pdf:

Acrobat Reader DC - PdfFormExample.pdf

Acrobat Reader DC - PdfFormExample.pdf

1.1.4 I could enter text in all fields of sample_barcoded_demo.pdf and the field contents were echoed in the box ‘Barcode Contents’ but the bar code itself was not visible:

Acrobat Reader DC - sample_barcoded_demo.pdf

Acrobat Reader DC - sample_barcoded_demo.pdf

So, in summary, Acrobat Reader DC is not a viable option if you have to deal with forms that include automatically-updating bar codes.

1.2 PDF-XChange Editor

This application from Canadian company Tracker Software Products supersedes their deprecated PDF-XChange Viewer and has additional features. Neither application is open-source, though. Some features only work fully if you purchase a software licence and enter the licence key. For example, if you add a signature to a PDF form (‘Document’ > ‘Signatures and Initials’) and then save it, DEMO stamps are added to the new PDF file (which still has editable fields). However, if you print the PDF form (either to a PDF file or to paper) then DEMO stamps are not added (but the new PDF file is not fillable/editable). Click on the two links below to view the sample PDF file PdfFormExample.pdf signed and saved to a new PDF file, and the sample PDF file PdfFormExample.pdf signed and printed to a new PDF file:

PdfFormExample_with_signature_added_then_Saved.pdf

PdfFormExample_with_signature_added_then_Printed_to_PDF.pdf

If you save them to disk and open them in PDF-XChange Editor, you will see the distinction.

As stated on the company’s Web site, the free application can be used for private and work purposes:

The FREE download of the PDF-XChange Editor may be used without limitation for Private, Commercial, Government and all uses, provided it is not: incorporated or distributed for profit/commercial gain with other software or media distribution of any type – without first gaining permission.

Below are screenshots of the four sample PDF forms opened in PDF-XChange Editor…

1.2.1 I could enter text in the three fields in acrobat8_barcodedforms.pdf, and the bar code was updated accordingly:

PDF-XChange Editor - acrobat8_barcodedforms.pdf

PDF-XChange Editor - acrobat8_barcodedforms.pdf

I used my smartphone’s Barcode Scanner app to read the bar code on the hard-copy form printed by PDF-XChange Editor:

Text1Text2Text3
I am able to change the text in these fields of this formto see how 2D barcodes work.

Notice that the layout of the encoded text is slightly different to the bar code generated by Adobe Acrobat Reader DC.

1.2.2 I could enter text in the three fields in barcode_field.pdf, and the three bar codes were visible:

PDF-XChange Editor - barcode_field.pdf

PDF-XChange Editor - barcode_field.pdf

I used my smartphone’s Barcode Scanner app to read the three bar codes on the hard-copy form printed by PDF-XChange Editor:

The PDF417 bar code was read as follows:

text_0:PDF417 barcode:I can enter text in these fields of this form and can see the three barcodes to the right of these fields in PDF-XChange Editor.

The Data Matrix bar code was read as follows:

text_1:Data Matrix barcode:
To change the barcode field to the right, type in this box. The barcode field to the right will reflect the contents of the text field as barcode after the text field lost the focus. To reset the contents of all barcode fields, cick the ‘Rset’ button.

Notice that the words ‘click’ and ‘Reset’ in the field were apparently not encoded correctly.

The QR Code bar code was read as a meaningless apparently random bunch of characters.

The PDF file and the three bar codes were generated on the fly by PHP code calling the pdflib library produced by the company PDFlib GmbH. I do not know how accurate this particular PDF file is, or how accurate is the Bar Code Scanner app on my smartphone.

1.2.3 I could enter text in the fields in PdfFormExample.pdf:

PDF-XChange Editor - PdfFormExample.pdf

PDF-XChange Editor - PdfFormExample.pdf

1.2.4 I could enter text in all fields of sample_barcoded_demo.pdf, and the field contents were echoed in the box ‘Barcode Contents’ and the bar code itself was visible:

PDF-XChange Editor - sample_barcoded_demo.pdf

PDF-XChange Editor - sample_barcoded_demo.pdf

I used my smartphone’s Barcode Scanner app to read the PDF417 bar code on the hard-copy form printed by PDF-XChange Editor:

Brian
S
Fitzgerald
Calle Fitzcarrald, 225
Iquitos

bsf@iquitos.nom.pe

So, in summary, PDF-XChange Editor appears to be a possible option in Windows 10, whether or not you have to deal with forms that include automatically-updating bar codes. I am quite impressed with the application.

2. Linux

2.1 Acrobat Reader 9

This is the free closed-source Linux application you can install via the Portage package manager (the package is app-text/acroread).

Below are screenshots of the four sample PDF forms opened in Acrobat Reader 9 for Linux.

2.1.1 I could enter text in the three fields in acrobat8_barcodedforms.pdf, and the bar code was updated accordingly:

Acrobat Reader 9 Linux - acrobat8_barcodedforms.pdf

Acrobat Reader 9 Linux - acrobat8_barcodedforms.pdf

I used my smartphone’s Barcode Scanner app to read the bar code on the hard-copy form printed by Acrobat Reader 9 for Linux:

Text1Text2Text3I am able to change the text in these fields of this form to see how 2D barcodes work.

2.1.2 I could enter text in the three fields in barcode_field.pdf, but the three bar codes were not visible:

Acrobat Reader 9 Linux - barcode_field.pdf

Acrobat Reader 9 Linux - barcode_field.pdf

2.1.3 I could enter text in the fields in PdfFormExample.pdf:

Acrobat Reader 9 Linux - PdfFormExample.pdf

Acrobat Reader 9 Linux - PdfFormExample.pdf

2.1.4 I could enter text in all fields of sample_barcoded_demo.pdf, and the field contents were echoed in the box ‘Barcode Contents’ but the bar code itself was not visible:

Acrobat Reader 9 Linux - sample_barcoded_demo.pdf

Acrobat Reader 9 Linux - sample_barcoded_demo.pdf

So, in summary, Acrobat Reader 9 for Linux is not a viable option if you have to deal with forms that include automatically-updating bar codes.

2.2 Okular

This is the well-known KDE document viewer application.

Below are screenshots of the four sample PDF forms opened in Okular.

2.2.1 I could enter text in the three fields in acrobat8_barcodedforms.pdf but the bar code was not visible:

Okular - acrobat8_barcodedforms.pdf

Okular - acrobat8_barcodedforms.pdf

2.2.2 I could enter text in the three fields in barcode_field.pdf but the three bar codes were not visible:

Okular - barcode_field.pdf

Okular - barcode_field.pdf

2.2.3 I could enter text in the fields in PdfFormExample.pdf:

Okular - PdfFormExample.pdf

Okular - PdfFormExample.pdf

2.2.4 I could enter text in all fields of sample_barcoded_demo.pdf but the field contents were not echoed in the box ‘Barcode Contents’ and the bar code itself was not visible:

Okular - sample_barcoded_demo.pdf

Okular - sample_barcoded_demo.pdf

So, in summary, Okular is not a viable option if you have to deal with forms that include automatically-updating bar codes. In fact, Okular was the worst of the bunch.

2.3 PDF-XChange Editor

To install this Windows application under WINE in Linux:

$ export WINEPREFIX=$HOME/.wine-pdfxve6
$ export WINEARCH="win32"
$ winecfg # Select Windows 10.
$ cd .wine-pdfxve6/drive_c/
$ # Copy downloaded installer to C: drive:
$ cp ~/Downloads/PDFXVE6.zip .
$ unzip PDFXVE6.zip
$ # Install PDF-XChange Editor:
$ wine PDFXVE6.exe

  • Click ‘Install’.
  • Click ‘Next’.
  • Select ‘I accept the terms in the License Agreement’ and click ‘Next’.
  • Click ‘Custom’.
  • Click ‘Browsers Plugins’ and select ‘Don’t install’. Click ‘Next’.
  • Leave ‘Create a Start Menu folder’ ticked. Untick ‘Create Desktop Icons.’ Untick ‘Set PDF-XChange Editor as default application for PDF files’. Untick ‘Set Printer “PDF-XChange Lite V6” As Default’. Click ‘Next’.
  • Select ‘Free Version’ and click ‘Next’.
  • Click ‘Install’.
  • Untick ‘Launch PDF-XChange Editor’ and click ‘Finish’.
  • Click ‘Close’.

KDE Plasma 5 then has an entry for PDF-XChange Editor in the Application Launcher under ‘Applications’ > ‘Wine’ > ‘Programs’ > ‘Tracker Software’. Alternatively, to launch PDF-XChange Editor from the command line, you should enter:

$ WINEPREFIX="$HOME/.wine-pdfxve6" && WINEARCH="win32" && wine $WINEPREFIX/drive_c/Program\ Files/Tracker\ Software/PDF\ Editor/PDFXEdit.exe

If you also want the Windows application running under WINE to be able to access PDF files on a NAS, i.e. to be able to open Samba shares, see my previous post How to enable a Windows application in WINE to access a Samba share on a NAS.

I will not bother showing screenshots of the four sample PDF files open in PDF-XChange Editor running under WINE in Linux, as the application’s behaviour is the same as in Windows (see the screenshots in sections 1.2.1 to 1.2.4 above). So, in summary, PDF-XChange Editor appears to be a viable option in Linux (albeit running under WINE), irrespective of whether or not you have to deal with forms that include automatically-updating bar codes.

3. Adding a signature to a soft copy of the PDF form

I am referring to a person’s written signature here, not to a digital signature. Rather than having to print the completed form on paper in order to sign it with a pen, then scan the fully-completed form in order to send it via e-mail, fax or whatever, many people wish to add their signature directly to the PDF form without having to print it. Below I explain the method I use to do this in both Linux and Windows.

3.1 Create a PNG file with your signature (one-time operation)

  1. Get a blank white piece of paper.
  2. Sign your name on the page.
  3. Scan the page with your scanner and save the image as a PNG file.
  4. Open the image with GIMP.
  5. Crop the image around the signature.
  6. Select ‘Layer’ > ‘Transparency’ > ‘Add Alpha Channel’.
  7. Select the Fuzzy Select Tool from the toolbox.
  8. Click on each white area and press the Delete key. Do this for the area around the signature and inside any loops. Obviously don’t click on the signature itself.
  9. Select ‘File’ > ‘Export’.
  10. Save the image as a PNG file.

3.2 Signing PDF documents

  1. Launch LibreOffice Draw and open the PDF file you wish to sign.
  2. Select ‘Insert’ > ‘Image…’ and select the PNG file of your signature. The image will be inserted.
  3. To move the signature around on the page, hover the mouse cursor over the image until the cursor changes to a red dot with four arrowheads, then click-and-hold to grab the image drag it.
  4. To reduce the size of the signature, hover the mouse cursor over the image until the cursor changes to a red dot with four arrowheads, then click and release. You will then see small blue ‘handles’ on the outline of the image. Hover the mouse cursor over a handle at one of the four corners of the image until the cursor changes to a Resize cursor. Click-and-hold and move the cursor to increase or decrease the size of the signature whilst maintaining the ratio of width to height.
  5. To save the completed and signed PDF form, select ‘File’ > ‘Export as PDF…’, click on ‘Export’ and give the file a name of your choice.

The new PDF file will contain all the information visible on the previous PDF file plus your written signature. However, unlike the original PDF file, you will not be able to modify any of the data. Therefore I recommend you retain a copy of the original PDF file before you added the signature, in case you wish to change any of field entries in future.

Note that the free PDF-XChange Editor can be used instead of LibreOffice Draw providing the PDF form is not secured or restricted, and providing you print it to a new PDF file using a virtual PDF printer driver. If the PDF form is secured or changes restricted, then use LibreOffice Draw as described above.

If you are using a PDF viewer that refuses to save your completed form as a PDF file after you have entered data in the fields (notice the message in the purple bar in the screenshots of Acrobat Reader 9 for Linux, for example), print the page to a PDF file instead by using the virtual PDF printer (‘Microsoft Print to PDF’ in Windows; CUPS ‘Virtual PDF Printer’ in Linux) at a resolution of e.g. 600 dpi (if possible). You should then be able to open that PDF file in LibreOffice Draw or PDF-XChange Editor to add your signature as explained above and print the signed form to a new PDF file.

Text too small in X Windows when using nvidia-drivers

In an earlier post titled ‘Switching between Intel and NVIDIA graphics processors on a laptop with NVIDIA Optimus hardware running Gentoo Linux‘ I described how I am able to switch between the closed-source NVIDIA video driver and the open-source Intel video driver on a Clevo W230SS laptop with NVIDIA Optimus hardware. This works nicely, but one thing had been niggling me for over a year: the size of the fonts in the Desktop Environment were much smaller when using the NVIDIA driver than when using the Intel driver. I could of course increase the font size via KDE’s ‘System Settings’ > ‘Font’ when using the NVIDIA driver, but then I would have to reduce the font size the same way when using the Intel driver. So I resolved to find a better way, and it turned out all I needed to do was add one line to the Monitor section in xorg.conf to specify the DPI (Dots Per Inch) for the X Screen when using the NVIDIA driver:

Section "Monitor"
    Identifier     "Monitor0"
    Option         "DPMS"
    Option         "DPI" "96 x 96"
EndSection

You can read more about this in the NVIDIA Accelerated Linux Graphics Driver README and Installation Guide, Appendix B. X Config Options.

As described in my earlier post, I run a script to copy a file I named xorg.conf.nvidia to xorg.conf when I want to use the NVIDIA driver, and another script to copy a file I named xorg.conf.intel to xorg.conf when I want to use the Intel driver. So all I needed to do was add the line Option "DPI" "96 x 96" to the Monitor section in the file xorg.conf.nvidia and run my script to switch to the NVIDIA driver. Problem finally solved.