Scripting a TeX document - (or other way to number pdf pages)

Florian Diesch diesch at spamfence.net
Wed Apr 14 04:19:43 UTC 2010


p.echols at comcast.net writes:

> My limited understanding of LaTeX is that you create a source file
> that has both text and markup.  That file is then interpreted when
> printed.  

It's not interpreted when printed but you use some kind of compiler to
create a printable file, e.g. a PDF file

> Would it be in the realm of realistic for someone such as
> yourself to identify the segments that would have to be in a script to
> do such a thing?  My analogy in "fake" html would be
>
> <document>
> <head>
> -Format code
> -Font Code
> -etc
> </head>
> <text position=bottom-left>
> Page Number 0001
> </text>
> <pagebreak><text position=bottom-left>
> Page Number 0002
> </text>
> <pagebreak><text position=bottom-left>
> Page Number 0003
> </text>
> </document>
>
> (For the critics, I am not good at html, but I know this is wrong, and why and that's not the point)
>
> The changing parts in such a page would be few, and the result easily
> scriptable.  For my purposes, I would not have to understand the LaTeX
> code for it to work.  Something you might think of as a fun challenge?

This short LaTeX source lets you assemble pages from multiple PDF files
and automatically adds a page number on each page:

--8<---------------cut here---------------start------------->8---
\documentclass[a4paper]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{pdfpages}
\usepackage{hyperref}

\begin{document}
\includepdfmerge[
                 picturecommand={\put(500, 30){Page Number \thepage}}
                ]{%
 some_file.pdf, 1-200,
 other_file.pdf, 5,7,10
}

\end{document}
--8<---------------cut here---------------end--------------->8---

The \put(500, 30) gives the position of the page number. Adapt it to
your needs. The text in the {} after gets put on every page; \thepage
is replaced by the page number.

The "some_file.pdf, 1-200" like lines include the given pages from the
given files. Every line except the last one has to end with comma.

Install the package texlive-latex-recommended to install a LaTeX system
with the needed LaTeX packages (expect it to take a few 100 MByte disc space).

Save the file as e.g. myfile.tex and run
 pdflatex myfile.tex
to create myfile.pdf


   Florian
-- 
<http://www.florian-diesch.de/software/pdfrecycle/>




More information about the ubuntu-users mailing list