我正在努力将每页 4 页的 PDF 恢复/撤消为每页 1 页的文档。
我之所以尝试撤消它,是因为我几乎无法阅读打印的文档。原始文件已按原样提供,我无意以舒适的格式打印它。
我通过搜索“PDF 讲义”和“PDF 多页”找到的几乎所有主题都提供将多个页面组装到一张纸中的功能。我正在尝试以完全相反的方式进行。
床单排列如下:
+----------------+
| Page 1 Page 2 |
| Page 3 Page 4 |
+----------------+
我想把他们变成:
+--------+
| Page 1 |
+--------+
| Page 2 |
+--------+
| Page 3 |
+--------+
| Page 4 |
+--------+
有什么想法或建议吗?
我感谢您的帮助:-)
答案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!"