Pdf

PDF 轉換:4 頁/張到 1 頁/張

  • October 12, 2020

我正在努力將每頁 4 頁 PDF 恢復/撤消為每頁 1 頁文件。

我試圖撤消它的原因是因為我幾乎無法閱讀列印的文件。原始文件已按原樣提供,我無意​​以舒適的格式列印它。

我通過搜尋“PDF 講義”和“PDF 多頁”找到的幾乎所有主題都提供將多頁組合成一張紙。我試圖以完全相反的方式進行。

床單排列如下:

+----------------+
| Page 1  Page 2 |
| Page 3  Page 4 |
+----------------+

我想把它們變成:

+--------+
| Page 1 |
+--------+
| Page 2 |
+--------+
| Page 3 |
+--------+
| Page 4 |
+--------+

有什麼想法或建議嗎?

我感謝您的幫助:-)

我終於找到了一個以前的執行緒(感謝Chris Hill),它幫助我編寫了以下腳本。這回答了我的問題:-)

#!/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!"

引用自:https://unix.stackexchange.com/questions/613963