想把PDF文件放在手机里看,但手机中的软件限制了500K的文件大小,无奈啊。
找找linux下的pdf处理软件吧。
今天找到了pdftk的软件,不仅仅可以分割PDF文件。可以上他的网页上看看去。
http://www.accesspdf.com/pdftk/
更妙的是,从这个页中还看到了VIM的PDF插件,偷着乐吧。
Vim users can also install my plug-in for easily editing PDF code. When you open a PDF in Vim, the plug-in calls pdftk to uncompress the page streams, so they are editable. When you save the PDF, the plug-in uses pdftk to repair and re-compress the PDF.
Download pdftk.vim.zip , unpack, and then move pdftk.vim into your Vim plug-ins directory (e.g., C:/vim/vim63/plugin ). Restart Vim to source the new plug-in.
太懒了,不翻译了。有需要的可以自己去看。
看来写插件的那个家伙是在windows下用的,如果你用的是linux,vim的脚本路径一般情况下应该在/usr/share/vim/vim72/plugin
下面写一个分割的例子
pdftk A=ARM-Architecture-Reference-Manual-v5-and-v6.pdf cat A39-108 output 1.pdf
A=表是要分割的PDF文件名
cat 后跟A39-108表示从39页到108页需要分割
output表示输出的那些页, 后面跟输出的文件名。
我自己写了个bash脚本,可以自己设定项,自动分割,默认情况下每一个分割后的文件为50页。
#!/bin/bash
IN=$1
#How many pages when you want to cut?
M=50
if [ -z $IN ]; then
echo "You must follow the pdf document after the command."
echo "Usage ./cut file.pdf"
echo "The test script it exit now."
exit 1
fi
which pdftk > pdftk.txt
if [ ! -s pdftk.txt ]; then
echo "The program pdftk is not installed, you should install it first."
echo "The test script it exit now."
rm pdftk.txt
exit 1
else
rm pdftk.txt
fi
INPUT=${IN%${IN: -4}}
if [ ! -d $INPUT ]; then
mkdir $INPUT
fi
pdftk $IN dump_data output ./$INPUT/report.txt
PAGE=`grep NumberOfPages ./$INPUT/report.txt`
PAGE=`echo $PAGE | cut -f 2 -d: `
for((i=1,j=1,k=1; i<=$PAGE; i++,j++,k++))
do
j=$(expr /( $i + $M - 1 /));
if [ $j -lt $PAGE ]; then
pdftk A=$IN cat A$i-$j output ./$INPUT/$k.pdf
else
pdftk A=$IN cat A$i-$PAGE output ./$INPUT/$k.pdf
fi
i=$(expr /( $i + $M - 1 /));
done
rm -rf ./$INPUT/report.txt