Alternative `pdftk multistamp` to `pdftk` once it's no longer available?
Asked Answered
B

2

6

I'm using pdftk multistamp on a server for adding custom page numbering, page headers and page footers to big (500-1200 pages) PDF files. I do this by counting number of pages in the input, creating suitable empty pages with page numbers, headers and footers using LaTeX and then use pdftk multistamp to combine the original PDF and the PDF with pages, headers and footers.

However, pdftk is based on libgcj (and gcj) and gcj is no longer maintained and has already been removed from GCC 7.1. As such, pdftk does not have any future as-is.

How to merge/combine PDF files in the future? I really would want to keep hyperlinks between pages working in resulting PDF files and metadata as much as possible.

Babbitt answered 8/6, 2018 at 7:56 Comment(0)
K
4

I started a Java port of pdftk a few months back; at this point it should have the same functionality as the C++ version but a lot more testing is needed. If you want to give it a try, check https://gitlab.com/pdftk-java/pdftk and file a bug report when it breaks.

Karykaryl answered 22/6, 2018 at 10:41 Comment(1)
Note that Ubuntu 20.04 LTS has this packaged in the official repos.Babbitt
H
0

I ran into the exact same issue, and ultimately landed on using the combine_pdf Ruby gem, which has a pretty simple API and works great. (Though I don't know how well it supports the hyperlinks and metadata you mention.) If that's an option for you, I'd highly recommend it. You should be good with a short script that looks something like this:

require "combine_pdf"
stamp_pages = CombinePDF.new(stamp_filename).pages
pdf = CombinePDF.new(base_filename)
pdf.pages.each_with_index do |page, index|
  page << stamp_pages[index > stamp_pages.size ? -1 : index]
end
pdf.save(output_filename)

Before that, I was using ImageMagick (which requires GhostScript for PDF manipulation), but I was losing a lot of detail in the conversion from PDFs to images and back:

# Increase the `-density` number for higher quality.
# Add `+antialias` to stop ImageMagick from antialiasing your images.
convert -density 300 base_filename null: stamp_filename -compose multiply -layers composite output_filename
Halvah answered 21/12, 2018 at 18:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.