rrthomas / pdfjam

The pdfjam package for manipulating PDF files
GNU General Public License v2.0
369 stars 27 forks source link

Adding (real) file name to every page? #83

Open gabrielastro opened 6 days ago

gabrielastro commented 6 days ago

First of all, thank you for this great script! Is there a way of adding to every output page the name of the original document? I am combining several one-page PDFs and important information is in the title of each document. Doing:

pdfjam --fitpaper true --pagecommand '\thispagestyle{headings} \markboth{\jobname}{\jobname}' -o AlleErgebnisse.pdf  Modell_*.pdf

leads to a PDF with "a" as title (and then also the page number of the global output PDF, which I was not expecting but is not the biggest problem). Using --no-tidy and looking in /tmp/pdfjam-…/ reveals the reason: pdfjam creates a temporary file named a.tex containing the include commands for the individual files. Is there a solution or a work-around? At worse in two steps, somehow first printing the file name on each individual document (onto a copy) and then combining those?

I am surprised that no one else seems to have asked this… Thanks!

lemniscati commented 5 days ago

pdfjam is a shell-script front end to the LaTeX 'pdfpages' package (for which, see http://www.ctan.org/tex-archive/macros/latex/contrib/pdfpages). (cf. https://github.com/rrthomas/pdfjam/blob/master/pdfjam-help.txt#L1-L2)

In particular, pdfjam is a wrapper script for using \includepdfmerge in the pdfpages package. So, I guess, if \includepdfmerge were able to do it, pdfjam would be also.

gabrielastro commented 5 days ago

Ok, that makes sense. Thanks! Maybe we can leave this open in case someone else has a solution (it does not seem easy with \includepdfmerge).

DavidFirth commented 5 days ago

Maybe this sort of thing could somehow be helpful?

pdfjam --pagecommand '' --preamble '\usepackage{fancyhdr} \pagestyle{fancy} \fancyfoot[c]{\texttt{the-file-name.pdf}} \usepackage[bottom=40pt]{geometry}' the-file-name.pdf

If that's the sort of thing you want, then it should be easily scriptable. The fancyhdr and geometry packages offer a lot of possibilities for headers, footers and their placement.

gabrielastro commented 4 days ago

Hello David, Thank you for your answer! That would need to be done for every document (i.e., every page of the final PDF collecting all documents) and then those temporary ones combined, yes? I guess one could script that (with a wrapper for pdfjam that uses pdfjam subprocesses, I guess). There are a few issues here:

  1. The fixed position of the footer (I am combining plots that are not a normal page width, and it would be nice for the command to not require manual setting of the footer position). For this, --fitpaper 'true' --pagecommand '\thispagestyle{headings} \markboth{\texttt{the-file-name.pdf}}{\texttt{the-file-name.pdf}}' is better, although the header is being put at some "random" position on the page
  2. The presence of underscores in the file name, which is quite a common thing (how to escape them without having to do it by hand?).

One would need to look into the options of fancyhdr (or headings) to see how to put the file name at the top or bottom of the (non-standard-sized) pages. I guess a wrapper script to pdfjam would be the way, and the best would be if it were possible to activate it with an option to pdfjam (--writefilenames [top|middle|bottom]-[left|right|centre] or so). Thanks, Gabriel