[Linux] Adding page number to PDF file in terminal

Note: You will lose all the links (hyperlink, internal-link) in PDF with this way

Create latex file numbered.tex:

\documentclass[letterpaper,12pt]{article}
\usepackage{pdfpages}
\usepackage{fancyhdr}
\usepackage{amsfonts}

\setlength\topmargin{-0.200in}
\setlength\headheight{0in}
\setlength\headsep{0in}
\setlength\textheight{9.5in}
\setlength\textwidth{7.0in}
\setlength\oddsidemargin{-0.25in}
\setlength\evensidemargin{-0.25in}

\pagestyle{fancy}
\fancyhf{}%
\renewcommand{\headrulewidth}{0pt}
\fancyfoot[R]{\thepage}

\begin{document}

\includepdf[pages=-,pagecommand={\pagestyle{fancy}}]{your_pdf_file.pdf}

\end{document}

Replace your_pdf_file.pdf by the PDF file you want to edit:

\includepdf[pages=-,pagecommand={\pagestyle{fancy}}]{your_pdf_file.pdf}

Running pdflatex will create a new file numbered.pdf which is your PDF file with page number:

$ pdflatex numbered.tex
This is pdfTeX, Version 3.14159265-2.6-1.40.21 (TeX Live 2020) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./numbered.tex
LaTeX2e <2020-02-02> patch level 5
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2019/12/20 v1.4l Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size12.clo))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pdfpages.sty
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/share/texlive/texmf-dist/tex/latex/tools/calc.sty)
(/usr/share/texlive/texmf-dist/tex/latex/eso-pic/eso-pic.sty
(/usr/share/texlive/texmf-dist/tex/generic/atbegshi/atbegshi.sty
(/usr/share/texlive/texmf-dist/tex/generic/infwarerr/infwarerr.sty)
(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty)
(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/xcolor/xcolor.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphicx.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/graphics.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/trig.sty)
(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/graphics.cfg)))
(/usr/share/texlive/texmf-dist/tex/latex/pdfpages/pppdftex.def))
(/usr/share/texlive/texmf-dist/tex/latex/fancyhdr/fancyhdr.sty)
(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty) (./numbered.aux)
(/usr/share/texlive/texmf-dist/tex/latex/epstopdf-pkg/epstopdf-base.sty
(/usr/share/texlive/texmf-dist/tex/latex/latexconfig/epstopdf-sys.cfg))
(/usr/share/texlive/texmf-dist/tex/latex/pdflscape/pdflscape.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/lscape.sty)) [1{/usr/share/texlive/texmf-dist/fonts/map/pdftex/updmap/pdftex.map}
...
Output written on numbered.pdf (19 pages, 1033039 bytes).
Transcript written on numbered.log.

If command shows error that *.sty files are missing, you need to install package which contains those *.sty files.

pdf  shell  latex 

See also

comments powered by Disqus