Home pdftk extract random pages from script variable
Reply: 0

pdftk extract random pages from script variable

user1254 Published in May 24, 2018, 4:00 pm

I have some pdf files about 2000 pages. They are randomly generated. I need to extract some pages that contain some specific patterns, that changes its page number for every pdf. With some steps using pdfToText and AWK, I can get the page numbers and I store some info into a csv file like that:

PatternA ; 1 3 5 7
PatternB ; 1 8 10 22

I have been trying to do a loop to get and process each line from this csv into the cat option from pdftk command, but it aways return error:

$IFS=$(printf '\n\t')
for line in `cat job.csv`
pattern=`echo $line ¦ cut -d ';' -f 1` 
pages=`echo $line ¦ cut -d ';' - f 2` 
pdftk input.pdf cat $pages output $pattern

When echoing pattern and pages variables, everything are ok. But the pdftk command returns error if I try to get pages from $pages variable:

Error: Unexpected text in page range end, here: 
   1 3 5 7
   Acceptable keywords, for example: "even" or "odd".
   To rotate pages, use: "north" "south" "east"
       "west" "left" "right" or "down"
Errors encountered.  No output created.
Done.  Input errors, so no output created.

What I am doing wrong?


You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.335458 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO