Linux – Bash Resize, split, Rotate or concatenate PDFs

This has probably been done a thousand times and ways, and much better than my humble fiddling. Consider this my memory pad for later.

I am doing some scripted pdf magic with files that come in from the scanner. They are either too big for web use, wrong format, not the right orientation (user error) or similar. So here’s a little collection:

Convert all (huge) PDFs into small ones with ghostscript (assuming ./Z-OLD for old versions exists):

for i in *.pdf; do gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$i-small.pdf $i; mv $i Z-OLD/; rename .pdf-small.pdf .pdf *-small.pdf; done

Convert all PNGs in working directory into small PDFs (assuming ./png exists):

for i in *.png; do convert $i $i.pdf; mv $i png/; gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/ebook -dNOPAUSE -dQUIET -dBATCH -sOutputFile=$i-small.pdf $i.pdf; rename .png-small.pdf .pdf *.png-small.pdf; rm *.png.pdf; done

Concatenate PDFs into one file (the last argument is the new outputfile):

pdfunite A.pdf B.pdf C.pdf ABC.pdf

A lazy “rotate all” script that helps me if I put the paper on the scanner the wrong way. Leaves four versions of every pdf it finds, but 90/180/270° degrees tilted to the original.

#!/bin/bash
INFILE=ls.txt
ls *pdf -1 > $INFILE
while IFS=”²” read -r line
do
PDF=`basename $line | rev | cut -c 5- | rev`
#left turn
pdftk “$line” cat 1-endwest output “$PDF”_left.pdf
#right turn
pdftk “$line” cat 1-endeast output “$PDF”_right.pdf
#turn 180 degrees:
pdftk “$line” cat 1-endsouth output “$PDF”_upsidedown.pdf
done <$INFILE

And yes, I know, there’s better ways. Worx 4 me, I guess. 🙂


NetworkManager and Wol (WakeOnLAN)

That one little moment when the last of the systems that had failed for years to wake up on LAN finally gives up and does the job. I literally have no idea what went wrong on this little media station in the past, but a fresh install of Opensuse Tumbleweed fixed it. We’ve been looking into the BIOS so many times, systematically, comparing with its twin sibling, didn’t find a mistake. And also the NetworkManager dispatcher script was installed. I gave up and did a fresh Linux install. All I had to do then was adding this script: 

#!/bin/bash
# /etc/NetworkManager/dispatcher.d/wol
#
#
# wol dispatcher script for NetworkManager
#
#
IFNAME=enp2s0
if [ $2 = “up” -a $1 = $IFNAME ]; then
sleep 2
/usr/sbin/ethtool -s $IFNAME wol g
fi

… and make it executable (chmod a+x), done. Oh, make sure that the line starting with “IFNAME” (line 8) contains YOUR device’s name, not the random generated by your distributor and that the script really ends up in /etc/NetworkManager/dispatcher.d/wol.

Now my little upgrade script (don’t do this on production machines!) wakes up and updates the media station every morning while we are sleeping (all relevant data changed):

#!/bin/bash
# /usr/sbin/wakeup-update-mediastation
#
# Wakeup and update MediaStation
wol a8:a1:23:3e:g7:39
sleep60
ssh 192.168.0.222 ‘sudo zypper ref && sudo zypper dup -y -l –allow-vendor-change
sleep20
ssh 192.168.0.222 ‘sudo sync; sudo poweroff
logger Mediastation successfully updated

It’s invoked by the cron job: 

0 6 * * * /usr/sbin/wakeup-update-mediastation

Your mileage may vary when it comes to user priviledges (sudo or ssh as root, make sure you do the right thing!)

Unlimited Screen Estate and machines at your mouse/kb, w/o KVMs, all in #opensource: #barrier

Barrier: A Free, Open-Source and Cross-Platform Alternative to Synergy

“You’ve probably heard of Synergy before. If you didn’t, Synergy is a piece of software that allows you to shares one mouse and one keyboard between multiple computers. A great piece of software that costs $29 for the basic version and $39 for the pro version. If you’d love to have the capabilities that Synergy provides but don’t want to fork over $29, you should check out Barrier which is free, open-source and cross-platform. Synergy started as an open source project. So the guys over at Barrier forked that original Synergy project, updated it and kept it’s minimalistic design.”

ER=EPR (german)

ER = EPRER=EPR – Wikipedia

“ER = EPR ist eine physikalische Vermutung, die besagt, dass zwei verschränkte Teilchen (ein sogenanntes Einstein-Podolsky-Rosen- oder EPR- Paar) durch ein Wurmloch (oder Einstein-Rosen-Brücke) [1] [2] verbunden sind und eine Basis sein können um Allgemeine Relativitätstheorie und Quantenmechanik zu einer Theorie von allem zu vereinen . [1] Die Vermutung wurde 2013 von Leonard Susskind und Juan Maldacena vorgeschlagen . [3] Sie schlugen vor, dass ein nicht durchquerbares Wurmloch (Einstein-Rosen-Brücke oder ER-Brücke) einem Paar maximal verschränkter Schwarzer Löcher entspricht . EPR bezieht sich auf Quantenverschränkung ( EPR-Paradox ).”

 

AdS/CFT-Korrespondenz HintergrundenÜbersicht der Korrespondenz

“In der theoretischen Physik ist die Anti-de-Sitter/konforme Feldtheorie-Korrespondenz , manchmal auch Maldacena-Dualität oder Eich/Schwerkraft-Dualität genannt , eine vermutete Beziehung zwischen zwei Arten von physikalischen Theorien. Auf der einen Seite stehen Anti-de-Sitter-Räume (AdS), die in Theorien der Quantengravitation verwendet werden , formuliert im Sinne der Stringtheorie oder M-Theorie . Auf der anderen Seite der Korrespondenz stehen konforme Feldtheorien (CFT), die Quantenfeldtheorien sind , einschließlich Theorien ähnlich den Yang-Mills-Theorien , die Elementarteilchen beschreiben. Die Dualität stellt einen großen Fortschritt im Verständnis der Stringtheorie und der Quantengravitation dar. [1] Dies liegt daran, dass es eine störungsfreie Formulierung der Stringtheorie mit bestimmten Randbedingungen bietet und weil es die erfolgreichste Realisierung des holographischen Prinzips ist , einer Idee in der Quantengravitation, die ursprünglich von Gerard ‘t Hooft vorgeschlagen und von Leonard Susskind gefördert wurde .”

Einstein-Podolsky-Rosen-Paradoxon – Wikipedia

“Das Einstein-Podolsky-Rosen-Paradoxon, auch EPR-Paradoxon, oder EPR-Effekt, ist ein im 20. Jahrhundert intensiv diskutiertes quantenmechanisches Phänomen. Der Effekt wurde nach Albert Einstein, Boris Podolsky und Nathan Rosen benannt, die dieses Phänomen im Rahmen eines Gedankenexperiments vorstellten. Zuweilen wird auch von einem EPR-Argument gesprochen. Es zeigt beispielhaft, dass die Quantenmechanik gegen die Annahme der Lokalität verstößt, die eine der Grundannahmen der klassischen Physik ist.”