Skip to content

Instantly share code, notes, and snippets.

@yudoufu
Last active July 15, 2021 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yudoufu/8a19824e3f8d647ce14eecd2585c8ccb to your computer and use it in GitHub Desktop.
Save yudoufu/8a19824e3f8d647ce14eecd2585c8ccb to your computer and use it in GitHub Desktop.
#!/bin/bash
set -euo pipefail
main() {
input=~/Downloads/testfifle.pdf
outdir="./thumb"
prefix="thumb"
rm -rf $outdir && mkdir -p $outdir
echo "---- single task"
single_runner $input $outdir $prefix
rm -rf $outdir && mkdir -p $outdir
echo "---- separated task"
separate_runner $input $outdir $prefix
}
separate_runner() {
local input=$1
local outdir=$2
local prefix=$3
rm -rf ./tmp && mkdir -p ./tmp
pagenum=$(pdfinfo $input |grep Pages | cut -f2 -d ':' | tr -d " \n")
echo "- separate to $pagenum pages"
time pdfseparate $input ./tmp/$prefix-%d.pdf
echo "- convert"
time seq 1 $pagenum | xargs -L 1 -P $pagenum -I {} pdftocairo -png -transp -r 150 -singlefile ./tmp/$prefix-{}.pdf $outdir/$prefix-{}
}
single_runner() {
local input=$1
local outdir=$2
local prefix=$3
time pdftocairo -png -transp -r 150 $input $outdir/$prefix
}
# call main.
main "$@"
@yudoufu
Copy link
Author

yudoufu commented Jul 15, 2021

---- single task

real	3m55.679s
user	3m52.611s
sys	0m2.387s
---- separated task
- separate to 145 pages

real	0m14.721s
user	0m13.487s
sys	0m1.191s
- convert

real	0m59.012s
user	7m15.378s
sys	0m29.138s

macは6coreなので早くて当たり前ではある。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment