Skip to content

Instantly share code, notes, and snippets.

@galatolofederico
Last active October 21, 2021 23:33
Show Gist options
  • Select an option

  • Save galatolofederico/3c709ad7fd6bca1073280d9b14f13964 to your computer and use it in GitHub Desktop.

Select an option

Save galatolofederico/3c709ad7fd6bca1073280d9b14f13964 to your computer and use it in GitHub Desktop.
Transform a presentation with animations in a pdf by automatically clicking and screenshotting
#!/bin/bash
#
# Transform a presentation with animations in a pdf by automatically clicking and screenshotting
#
presentation_window_name="WPS Presentation Slide Show"
output_file="presentation.pdf"
tmp_folder="./presentation-to-pdf-tmp"
click_delay=0.2
trim=1
check_command(){
if [ -z "$(command -v $1)" ] ; then
echo "This script needs $1, please install it"
exit
fi
}
check_command xdotool
check_command escrotum
check_command convert
echo "Make sure that the presentation window is visible you can run this script in the background while focusing the presentation window"
id=$(xdotool search --name "$presentation_window_name" | sed 1q)
if [ -z $id ]; then
echo "Make sure that the presentation window is open and that the presentation window name matches '$presentation_window_name' (you can use xprop to check)"
exit
fi
rm -rf "$tmp_folder"
mkdir "$tmp_folder"
i=0
while xwininfo -id "$id" > /dev/null; do
echo "Saving slide $i"
escrotum -x "$id" "$tmp_folder/$i.png" > /dev/null 2>&1
xdotool click --window "$id" 1 > /dev/null
sleep "$click_delay"
i=$((i+1))
done
if [ "$trim" -eq 1 ]; then
for slide in "$tmp_folder"/*; do
echo "Trimming slide $slide"
convert "$slide" -fuzz 20% -trim "$slide"
done
fi
slides=$(ls -1vd $tmp_folder/* | tr "\n" " ")
echo "Creating pdf"
convert $slides $output_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment