Search code examples
pdffooterenscript

Linux enscript -- footer doesn't work (final purpose is to add pager number at footer for PDF)


Does anybody know how to add page number at footer for PDF? Followed is an example to show how to add page number at header by using enscript, ps2pdf pdftk. It works.

#!/bin/bash
input="$1"
output="${1%.pdf}-header.pdf"
pagenum=$(pdftk "$input" dump_data | grep "NumberOfPages" | cut -d":" -f2)
enscript -L1 --header='|Page $% of $=|' --output - < <(for i in $(seq "$pagenum"); do echo; done) | ps2pdf - | pdftk "$input" multistamp - output $output

According to enscript's manual, changing --header to --footer will work for footer. But in fact, no matter how I set the option for --footer, there is no footer at all. What's the matter? Does --footer work for enscript?


Solution

  • Someone posted a good example of a working .hdr file on askubuntu along with alternative ways to invoke the new header file. https://askubuntu.com/questions/544606/printing-footers-using-enscript

    % -- code follows this line --
    %Format: fmodstr    $D{%a %b %d %H:%M:%S %Y}
    %Format: pagenumstr $V$%
    
    %HeaderHeight: 38
    %FooterHeight: 15
    
    /do_header {   % print default simple header
    
    % Footer
    gsave
      d_footer_x d_footer_y HFpt_h 3 div add translate
      HF setfont
    
      user_footer_p {
        d_footer_x  d_footer_y moveto user_footer_left_str show
    
        d_footer_w user_footer_center_str stringwidth pop sub 2 div
        0 moveto user_footer_center_str show
    
        d_footer_x d_footer_w add user_footer_right_str stringwidth pop sub
        d_footer_y moveto user_footer_right_str show
      } if
    grestore
    
    % Header
    gsave
      d_header_x d_header_y HFpt_h 3 div add translate
      HF setfont
    
      user_header_p {
        5 0 moveto user_header_left_str show
    
        d_header_w user_header_center_str stringwidth pop sub 2 div
        0 moveto user_header_center_str show
    
        d_header_w user_header_right_str stringwidth pop sub 5 sub
        0 moveto user_header_right_str show
      } {
        5 0 moveto fname show
        45 0 rmoveto fmodstr show
        45 0 rmoveto pagenumstr show
      } ifelse
    grestore
    
    } def