[Linux] Đánh số trang cho file PDF từ terminal

Chú ý: Link trong file PDF (hyperlink, internal-link) sẽ bị mất nếu làm theo cách này

Tạo một file numbered.tex với nội dung như sau:

\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}

Thay your_pdf_file.pdf bằng file PDF mà các bạn muốn chỉnh sửa:

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

Chạy lệnh pdflatex với file trên. Nó sẽ tạo ra một file PDF mới với tên là numbered.pdf chính là file PDF của bạn sau khi được thêm đánh số trang:

$ 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.

Nếu câu lệnh bị lỗi và báo thiếu các file *.sty, các bạn cần cài các gói có chứa những file *.sty đó.

pdf  shell  latex 

Bài liên quan

comments powered by Disqus