shithub: pdffs

Download patch

ref: 12d4d90f79385a358e03d3a6d5e8bbec06aeeda5
parent: ccb4d1dcbe56987eaccd49bb56d1aabe5a2dfd13
author: Noam Preil <noam@pixelhero.dev>
date: Wed Jun 2 11:15:46 EDT 2021

add page number finder

--- /dev/null
+++ b/pdfpages.rc
@@ -1,0 +1,34 @@
+#!/bin/rc
+file=$1
+target=$2
+if(~ $#file 0 || ~ $#target 0){
+	echo Usage: pdfpages.rc file.pdf '''search string'''
+	exit
+}
+if(! test -f $file){
+	echo $file does not exist
+	exit
+}
+current=0
+fn checkpage{
+	if(pdffs $file $* " | grep -s $target)
+		echo $current
+}
+fn checkpages{ 
+	count=`{pdffs $file $* Count}
+	i=0
+	while(! ~ $i $count){
+		current=`{echo $current '+ 1' | bc}
+		type=`{pdffs $file $* Kids $i Type}
+		if(~ $type /Page)
+			checkpage $* Kids $i
+		if not if(~ $type /Pages)
+			checkpages $* Kids $i
+		if not{
+			echo Invalid type $type
+			exit
+		}
+		i=`{echo $i '+ 1' | bc}
+	}
+}
+checkpages Root Pages