2

I use a bash script to auto-generate a pdf calendar each month.I use the wonderful remind program as the basis for this routine. Great as are the calendars I get using that program, I need a more detailed header for the calendar (than just the name of the month and the year). I couldn't puzzle out a way to get the remind program to enhance the header, but I was able to get the enhanced results I wanted by creating a second pdf containing the header enhancements I need, then overlaying that pdf onto the calendar I produce with remind, via the pdftk utility (pdftk calendar.pdf stamp calendar_overlay.pdf output MONTH-YEAR-cal.pdf). Unfortunately, I recently lost the ability to use pdftk since keeping it on my system would necessitate me ceasing to do other system updates. In short, I had to remove it in order to continue updating my system.

So now I'm looking for some alternative that I can incorporate into my bash script. I am not finding any utility that will allow me to overlay one pdf with another, like pdftk allows. It seems I may be able to do something like what I'm after using imagemagick (-convert), though I would likely need to overlay the pdf with an image file like a .jpg rather than with a pdf. Another possible solution may be to use TeX/LaTeX to insert text into the pdf as described at https://rsmith.home.xs4all.nl/howto/adding-text-or-graphics-to-a-pdf-file.html.

I wanted to ask here, before investing a lot of time and effort into pursuing one or other of the two potential options I've identified, whether there is some other way, using command line options that can be incorporated into a bash script, of overlaying one pdf with another in the manner described? Input will be appreciated.

LATER EDIT: another link with indications how to do such things using LaTeX https://askubuntu.com/questions/712691/batch-add-header-footer-to-pdf-files

M. Justin
  • 14,487
  • 7
  • 91
  • 130
MJiller
  • 149
  • 9
  • ImageMagick is not a vector to vector processor. ImageMagick will rasterize your input PDF files and then put the raster image back into a PDF vector shell. So that is not the best way to do it. – fmw42 Dec 26 '17 at 03:12
  • Shouldn't you rather figure out how you can keep pdftk *and* update your system? – Benjamin W. Dec 26 '17 at 03:16
  • 1
    Not a simple matter. libgcj has been removed from the latest gcc (see https://www.phoronix.com/scan.php?page=news_item&px=GCC-Patch-To-Drop-GCJ) and my system will depend for certain operations on the presence of the latest gcc. So I can't add back the library pdftk needs without downgrading gcc. Downgrading would be the first in a series of kludges that would later undoubtedly lead to big headaches. – MJiller Dec 26 '17 at 04:46
  • Some preliminary experimentation with LaTeX is producing promising results. I should be able to do something close to what I'm after using it, though incorporating this into my bash script will make this task a lot more complex than it was using pdftk. Off to the LaTeX forum to see what sort of help I can get there. – MJiller Dec 27 '17 at 00:02

2 Answers2

0

Assuming for simplicity that both of your files are of size 500pt x 200pt, you can use pdfjam with nup and delta options to trick it into overlaying your source pdf files.

pdfjam bottom.pdf top.pdf --outfile merged.pdf \
    --nup "1x2" \
    --noautoscale true \
    --delta "0 -200pt" \
    --papersize "{500pt, 200pt}"

Unfortunately, I've found in my tests that I needed to increase the y delta by one point to get perfect alignment.

none_00
  • 196
  • 5
  • Finally got around to trying this. I replaced the point sizes with ones for landscape letter paper (792 and 612, respectively) and it worked great! Unfortunately, pdfjam and related scripts are not packaged under the distro on which I want to run this script (I tested the suggestion on another computer with a distro that does have the package). But it looks like binaries can be downloaded, so that may not present much of a problem. Meanwhile I discovered a way to do this sort of thing using TeX and have been using that method. Thanks for the suggestion. – MJiller Mar 26 '18 at 16:07
  • Just a heads up that I'm contributing an adjusted version of this to tldr, since I also found your example very helpful :) https://github.com/tldr-pages/tldr/pull/5789 – xeruf Apr 19 '21 at 11:58
0

pdftk-java is a Java-based port of pdftk which looks to be actively in development. Given that its only real requirement appears to be Java 7+, it should work even in environments such as your own that no longer support the requirements of pdftk, so long as they have a Java runtime installed.

M. Justin
  • 14,487
  • 7
  • 91
  • 130