Desk with two ultra-wide-screens

Add Unlisted screen resolution using xrandr

Published / by Gert Pellin / Leave a Comment

The problem

On my desctop computer I have 2 ultra-wide-screens from LG, one connected with HDMI, the other with DVI.
The HDMI screen works fine out of the box but the DVI screen gets recognized as a normal wide-screen. After some googling I found the solution to add the resolution manually to my Linux system.

Getting the right configurations using xrandr

first run

$ xrandr

this will give output like this:

Screen 0: minimum 320 x 200, current 5120 x 1080, maximum 8192 x 8192
HDMI1 connected 2560×1080+2560+0 (normal left inverted right x axis y axis) 677mm x 290mm
1920×1080 60.00*
1680×1050 59.88
1600×900 59.98

HDMI2 connected 2560×1080+0+0 (normal left inverted right x axis y axis) 677mm x 290mm
2560×1080 60.00*+
2560x1080_60.00 59.98
1920×1080 60.00 50.00 59.94 30.00 29.97
1920x1080i 60.00 50.00 59.94

to add 2560×1080 to HDMI1 first run the next command

$ cvt 2560 1080

sample output:

2560×1080 59.98 Hz (CVT) hsync: 67.17 kHz; pclk: 230.00 MHz
Modeline “2560x1080_60.00” 230.00 2560 2720 2992 3424 1080 1083 1093 1120 -hsync +vsync

now you need to use this output to test the resolution and than add the settings for use in the next sessions.

Test before configuring


$ xrandr –newmode “2560x1080_60.00” 230.00 2560 2720 2992 3424 1080 1083 1093 1120 -hsync +vsync

$ xrandr –addmode HDMI1 2560x1080_60.00
$ xrandr –output HDMI1 –mode 2560x1080_60.00

finalising the configuration

if it works you can add it to the xorg configuration

$ sudo vim /etc/X11/xorg.conf.d/40-monitor.conf


$ sudo vim /usr/share/X11/xorg.conf.d/40-monitor.conf

Section "Monitor"
Identifier "HDMI1"
Modeline "2560x1080_60.00"  230.00  2560 2720 2992 3424  1080 1083 1093 1120 -hsync +vsync
Option "PreferredMode" "2560x1080"

I also posted this solution on stackexchange, as an answer to my own question.
For more information about the xrandr command you can take a look at the man page.

Tesseract OCR

Adding OCR to a multipage pdf

Published / by Gert Pellin / Leave a Comment

PDF of images

Nothing is more frustrating than a PDF book/course existing of scanned images. It’s impossible to search the text or to copy parts of the texts. Luckily there is something called OCR (Optical Character Recognition). With this technology it is possible to extract text out of images. The most popular application to do this in Linux is tesseract. But looking at its man page, we immediately see 1 big problem… it does not work on PDF files!

Get rid of the PDF format

So the first thing we have to do is to dispose of the pdf format and adopt the tiff format. This is very simply done with the gs command. But before making a bunch of new files, let’s make a temporary working directory.

mkdir ./tmptiff
/usr/bin/gs -sDEVICE=tiff24nc -r200 -o ./tmptiff/outfile-\%02d.tiff infile.pdf
cd ./tmptiff

Add OCR and make one searchable PDF file

If you take a look now in the tmptiff folder, you will see a bunch of tiff files with the pages of the PDF. Now we are able to give the files a OCR layer and to put them together again in one PDF file. This part is possible with a script I found online. to bad the person that made the script did not think of 1 thing, leading zero’s to prevent messing up the page order! Luckily I had this problem once before so I decided to add my previous function to the script…

Or we could do it the easy way!

And afterwards it all seamed to be to much work for something very simple! There is something as a multipage tiff format, so the following will do everything we need:

gs -sDEVICE=tiff24nc -r200 -o out.tif -dUseBigTIFF infile.pdf
tesseract -psm 1 -l eng out.tif outwithocr.pdf pdf



Book-binging script

Bash for Book-binding

Published / by Gert Pellin / 2 Comments on Bash for Book-binding

Book-binding using bash

3 Years ago I decided I wanted to make a big change in my live. I wanted to do what I always seamed to do best, work with computers, more specifically, I wanted to learn more about Linux and programming. There was only one problem, I hate reading long texts on a screen, leave alone entire books… So first thing I did was write me some scripts to transform pdf files that way it could be printed to bind it later as a real book the book-binding way .

In this post I will evaluate my script for people who are interested in it to do similar things in Bash. The script is only tested in native Linux, not in the bash included in Windows.

Making the preparations


// Make the temporary directory and cd into it
mkdir ~/$tmpdir
cd ~/$tmpdir

First off we have to tell some important things to the script. On line 1 we pass the current directory (where we run the script, not where te script is located) the workingdir variable.
We also need a temporary directory to store some files, to make sure we have a empty directory to work in, we give it a random part in its name.
To know the source file to work with we read the first argument given with the command. The file to save to will be customizable in the final version of the script, but for now, to keep it simple, we will work with binding.pdf. In the final version we will also look if the output file already exists.

Making the bundles

// Create a postscript version of the source file
pdftops $workingdir/$sourcefile

// Bundle the pages of the postscript file
declare -i bundlenr=1
for (( i=1; i < `pdfinfo $workingdir/$sourcefile | grep Pages | sed 's/[^0-9]*//'`; i=$i+32 )); do
    psselect -q -p`declare -i j=$i
                while (($j < $i+31)) do j=$j+1 done if (( `gs -o /dev/null -sDEVICE=bbox out${bundlenr}.ps 2>&1 | grep HiResBoundingBox | wc -l` < 6 )) then psjoin out$(( $bundlenr-1 )).ps out${bundlenr}.ps > out$(( $bundlenr-1  ))
        mv out$(( $bundlenr-1 )) out$(( $bundlenr-1 )).ps 
        rm out$(( $bundlenr )).ps

// Remove the temporary postscript source file

add_leading_zero "out" ".ps"

for file in ./out*.ps
    psbook $file | psnup  -b1.4cm -s0.6 -pa4 -2 > book_$
    ps2pdf book_$ book_$bundlenr.pdf

The first thing we still have to do before we can start editing the file is to make a postscript version of it. The reason is pdf is a proprietary format owned by Adobe and so there are not that many good editing applications laying around for it as there are for postscript.
Once we have or ps file the magic can begin, from line 6 to 23 a loop will iterate over the file to make little bundles of it that are small enough to sew them together later on, if your book leaves your printer! I will not go over the details of this for-loop, if you are interested in this part you should take some time to figure it out four yourselves.

Afterwards we can dismiss of the postscript source file, and, very important, we should add some leading zeros to the bundle file to make it easier ordering them. The function to do this will be given later on. from now on we are going to work with pdf again, so we make a pdf version of all the bundles.

The finishing touch

add_leading_zero "book_" ".pdf"
pdfunite `echo ./book_*.pdf` book.pdf
mv book.pdf $outfile
cd $workingdir
rm -rf ~/$tmpdir

The bundles now are ready, but it would be nice to have it all back in one file, so that’s exactly what the last part of the script is for. After reuniting the bundles into the output file, the temporary files can be safely removed.

bash does not know add_leading_zero!!

function add_leading_zero {
baseprefix=$(basename $prefix | sed -e 's/[]\/()$*.^|[]/\\&/g')
dirprefix=$(dirname $prefix)
for filename in "$prefix"*"$suffix"
    base=$(basename "$filename")
    index=$(echo "$base" | sed -rn "s/$baseprefix([0-9]+)$suffix$/\1/p")
    newbase=$(printf "$baseprefix%04d$suffix" $index)
    mv $filename "$dirprefix/$newbase"

We still have to make the function to add the leading zero where necessary, that is what this script will do. As you can see it takes exactly two arguments, the part of the filename before and after the number in the filename.

The full script

On github you can find the full working version. You can see it has some extra options that I added to it in time.

If you think it is still missing something or you know a better way to do some parts of it, please feel free to contribute to it on github

If you like some more information about book-binding, you can take a look here