Преобразование PDF :4 страницы/лист в 1 страницу/лист

УСТАНОВИТЬ:

В Fedora 29 у меня работает следующее!

# Install Requirements
sudo dnf install \
            xdotool \
            wmctrl \
            git

# Add Groups
sudo gpasswd -a $USER input
exec sg input newgrp $(id -gn)

# Add Multitouch Gestures
ORG_DIR=$PWD
cd /usr/src
sudo git clone https://github.com/bulletmark/libinput-gestures.git
cd libinput-gestures
sudo make install
libinput-gestures-setup autostart
libinput-gestures-setup start
cd $ORG_DIR

NOTE: There should be no errors, if there are logging out and back in fixes the issue.


КОНФИГУРАЦИЯ:

Для настройки параметров скопируйте /etc/libinput-gestures.confв ~/.config/libinput-gestures.confи отредактируйте при необходимости.

0
11.10.2020, 16:35
1 ответ

Наконец-то я нашел прежний тред (Благодаря Крису Хиллу ), который помог мне написать следующий сценарий. Что отвечает на мой вопрос:-)

#!/bin/bash
#
# Usage./<script name>.sh <source file>.pdf
#
# Slices each page from the <source> into 4 pages; then,
# Reassemble the slices into output.pdf; and, finally,
# Clean up the mess
#

echo "Working directory creation..."
mkdir -p tmp
echo "... done!"
echo

# Split source into multiple files
echo "Splitting source..."
cd tmp
pdftk "$1" burst
echo "... done!"
echo

# Slice each page into multiple files
echo "Reading doc_data.txt..."
pw=`cat doc_data.txt  | grep PageMediaDimensions | head -1 | awk '{print int($2)}'`
ph=`cat doc_data.txt  | grep PageMediaDimensions | head -1 | awk '{print int($3)}'`
w2=$(( pw / 2 ))
h2=$(( ph / 2 ))
w2px=$(( w2*10 ))
h2px=$(( h2*10 ))
echo "... done!"
echo

for f in  pg_[0-9]*.pdf ; do
    echo "Slicing file: ${f}..."

    # Name outputs so that they can be reassembled in order
    ulf="$( echo "$f" | cut -f 1 -d '.')_1.pdf"
    urf="$( echo "$f" | cut -f 1 -d '.')_2.pdf"
    dlf="$( echo "$f" | cut -f 1 -d '.')_3.pdf"
    drf="$( echo "$f" | cut -f 1 -d '.')_4.pdf"

    # Up-Left page
    echo "... into page ${ulf}"
    gs -o ${ulf} -sDEVICE=pdfwrite -g${w2px}x${h2px} -c "<</PageOffset [0 -${h2}]>> setpagedevice" -f ${f}

    # Up-Right page
    echo "... into page ${urf}"
    gs -o ${urf} -sDEVICE=pdfwrite -g${w2px}x${h2px} -c "<</PageOffset [-${w2} -${h2}]>> setpagedevice" -f ${f}

    # Down-Left page
    echo "... into page ${dlf}"
    gs -o ${dlf} -sDEVICE=pdfwrite -g${w2px}x${h2px} -c "<</PageOffset [0 0]>> setpagedevice" -f ${f}

    # Down-Right page
    echo "... into page ${drf}"
    gs -o ${drf} -sDEVICE=pdfwrite -g${w2px}x${h2px} -c "<</PageOffset [-${w2} 0]>> setpagedevice" -f ${f}

    echo "... done!"
    echo
done

# Merging sliced page into a single PDF file
echo "Reassembling the PDF file..."
ls -1 pg_[0-9]*_[1-4].pdf > fl
pdftk $( cat fl ) cat output output.pdf
echo "... done!"
echo

# Cleaning up
echo "Cleaning up..."
mv output.pdf..
cd..
rm -fr tmp
echo "... done!"
echo

echo "It's all done... you lucky man!"
0
18.03.2021, 22:58

Теги

Похожие вопросы