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

Aart Koelewijn aart at mtack.xs4all.nl
Wed Apr 14 19:00:09 UTC 2010


On Wed, 14 Apr 2010 17:29:34 +0000, p.echols wrote:

> ----- "Florian Diesch" <diesch at spamfence.net> wrote:
> 
>> 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
> 
> Thanks!  This is a great answer.  Similar to Aart's solution, I think
> that this would all be "scriptable."  As I am thinking through the
> parameters I would want, it is more of a scripting challenge than doing
> an add on to the prior existing script.  But it is also a more elegant
> solution in that it would do everything in one pass, rather than taking
> the "Brute Force" approach of blowing up the original pdf, "stamping"
> the pages, and then putting it back together.
> 
> A couple of questions if you don't mind.
> 
> Can you change the page size in the middle of a document?  For example,
> if file1.pdf is "us-letter" and file2.pdf is "us-legal", could the tex
> file be written in a way to change the number location so that the
> number ends up the same distance from the bottom of each page?
> 
> Here is my other question.  I think I need to read some LaTeX
> documentation on my own.  (Especially since I am sure to have more
> questions.)  Given what you know about what I am trying to do, can you
> suggest a good resource?
> 
> Thanks again,
> 
> --PE

The book I always use is "The LaTeX Companion" from Addison Wesley. I got 
a second printing from 1994 which doen't have much about pdf, but I'm 
sure there will be a more recent version.

Aart





More information about the ubuntu-users mailing list