20 lines
		
	
	
		
			800 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			20 lines
		
	
	
		
			800 B
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/bin/zsh
 | 
						|
# Split a PDF file in two at a specified page
 | 
						|
# 1 original PDF file path
 | 
						|
# 2 last page of first section (second section will start with the one after that)
 | 
						|
source ~/.local/lib/pdf_tools.sh
 | 
						|
 | 
						|
typeset -r             numpages=$(pdf_num_pages $1)
 | 
						|
typeset -r             digits=$#numpages
 | 
						|
typeset -r -Z${digits} m=$2
 | 
						|
 | 
						|
(( $2 > ${numpages} )) && echo "The document is only ${numpages} pages long, which is less than $2!" && exit 1
 | 
						|
(( $2 == ${numpages} )) && echo "The document is exactly ${numpages} pages long!\nNo action taken." && exit
 | 
						|
 | 
						|
typeset -r             stem=${1%.pdf}
 | 
						|
typeset -r -Z${digits} one=1
 | 
						|
typeset -r -Z${digits} n=$(( m + 1 ))
 | 
						|
 | 
						|
pdf_extract_range "$1" 1 ${m} "${stem}_${one}-${m}.pdf" > /dev/null
 | 
						|
pdf_extract_range "$1" ${n} ${numpages} "${stem}_${n}-${numpages}.pdf" > /dev/null
 |