Skip to main content
added 10 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff -ms document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer margin height, so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates a pdf which is then piped into pdftk via stdin - and, multistamped onto the input file and finally written to the output file.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff -ms document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer margin height, so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates a pdf which is then piped into pdftk via stdin - and multistamped onto the input file and written to the output.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff -ms document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer margin height, so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates a pdf which is then piped into pdftk via stdin -, multistamped onto the input file and finally written to the output file.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

deleted 3 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff -ms document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer margin height and, so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates a pdf which is then piped into pdftk via stdin - and multistamped onto the input file and written to the output.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer height and so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates a pdf which is then piped into pdftk via stdin - and multistamped onto the input file and written to the output.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff -ms document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer margin height, so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates a pdf which is then piped into pdftk via stdin - and multistamped onto the input file and written to the output.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

deleted 221 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer height and so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates an emptya pdf which is then piped into pdftk via stdin - and multistamped onto the input file and written to the output.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff document with empty pages except the footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer height and so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates an empty pdf which is then piped into pdftk via stdin and multistamped onto the input file and written to the output.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

An update for the revised question...

#!/bin/bash

label="$1"    #the label to be added to the footer
from=$2       #the starting number

#for each pdf in this directory
for input in *.pdf; do

  #compose an output file name
  output=${input%.*}.numbered.pdf
  
  #count the pages
  pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
  
  #calculate the last page no
  to=$(($from+$pagenum-1))
              
  (echo -e ".nr FM 0.125i\n.ds CH"; for s in $(seq -f "%05g" $from $to); do 
       echo -e ".ds RF $label $s \n.bp +1"; done) | 
       groff -ms -Tpdf | 
       pdftk "$input" multistamp - output "$output" 

  #get ready for the next file  
  from=$((to +1))
done

Compose a basic groff document with empty pages except the right footer .ds RF containing the desired text $label $s where $s is the page number which I padded with 0's in seq -f "%05g"

groff -ms macro applies a page header which is suppressed with .ds CH and .nr FM 0.125 reduces the footer height and so each "page" is just the footer with a page break .bp +1

Piping this text into groff -Tpdf creates a pdf which is then piped into pdftk via stdin - and multistamped onto the input file and written to the output.

My apologies to anyone who actually knows how to use groff properly if this is a hack .... I never even looked at it until today.

deleted 221 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29
Loading
added 28 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29
Loading
added 6 characters in body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29
Loading
edited body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29
Loading
edited body
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29
Loading
Source Link
bu5hman
  • 4.9k
  • 2
  • 16
  • 29
Loading