0

I am working with over thousands PDF files for a Sheet Music publisher.

All of these PDF files needs a preview PDF. A watermark for PDF files can easily be removed so I am asking for a true way to watermark our PDF:s in a batch operation.

PDF->Apply Watermark->JPG->Back to PDF

How can I do this? Is there a good tool for this operations?

  • Questions asking us to recommend or find tools, software libraries or other off-site resources are off-topic according to the [help/on-topic] guidelines. – Ken White May 05 '22 at 02:03
  • 1
    @KenWhite, from your help-center link, why don't these apply: "* software tools commonly used by programmers; and is * a practical, answerable problem that is unique to software development"? – Zach Young May 09 '22 at 20:36
  • *software commonly used by prrogrammers* refers to compilers, IDEs, etc., not general software. And questions about **using** software are different from questions asking to **recommend** tools or software, which is what your question asks. It's spelled out very clearly and specifically in the [help/on-topic] pages, specifically in item #3 in the section with the numbered list on that page. Selectively quoting contents of the page while ignoring the remainder of that page is not helping you here. – Ken White May 09 '22 at 20:51
  • 1
    @KenWhite, I’m not OP, and I genuinely brought up those points because I thought they were valid and should guide us towards answering this question. I’ll think about what you said. Thank you. – Zach Young May 09 '22 at 22:43

2 Answers2

0

The free route

ImageMagick can do the complete process for you, especially with the composite command's -watermark operator.

#!/bin/sh

# ImageMagick will pick the correct conversion formats based on filename suffixes, or maybe actual binary content?
InputPDF=$1
WatermarkImg=$2
OutputPDF=$3

pdfToImage=pdfToImage.png
imageWithWatermark=imageWithWatermark.png

# Convert PDF to image
convert           \
   -density 300   \
   -trim          \
    "$InputPDF"   \
   -quality 100   \
   -flatten       \
   -sharpen 0x1.0 \
   $pdfToImage

# Add watermark to intermediate image
composite          \
   -dissolve 15    \
   -tile           \
   "$WatermarkImg" \
   $pdfToImage     \
   $imageWithWatermark

# Convert intermediate image back to PDF
convert                \
   $imageWithWatermark \
   "$OutputPDF"

# Clean up
rm $pdfToImage $imageWithWatermark

I find the PDF to image conversion acceptable in terms of quality, though you can see some differences when looking at the before and after side-by-side, especially in how bolded glyphs seem less bold:

enter image description here

You can check this good post and its answers for a number of options for converting a PDF to an image, Convert PDF to image with high resolution.

I checked out PDFtoPPM, which was also highly mentioned in that thread, and I still see some degrading of the bolded fonts when converted:

enter image description here

Some more tiling Magick

I used this copyright symbol from Wikimedia Commons and this ImageMagick script:

#!/bin/sh

Infile="Copyright.png"
Outfile="Copyright_tiled.png"

h2=$(convert $Infile -format "%[fx:round(h/2)]" info:)

convert $Infile                   \
    \( -clone 0 -roll +0+"$h2" \) \
    +append                       \
    -write mpr:sometile           \
    +delete                       \
    -size 1224X1584               \
    tile:mpr:sometile             \
$Outfile

to create this staggered tiling (1224X1584 is the page size (8.5in x 11in) multiplied by 72 px/in, times 2 for a good density of tiles):

enter image description here

Zach Young
  • 10,137
  • 4
  • 32
  • 53
  • 1
    I’d really appreciate whoever voted this down explaining what’s wrong/lacking, giving me the chance to correct it, and give the community some food for thought on why they may not want to follow what I’ve laid out. – Zach Young May 09 '22 at 22:50
0

And here it is unwatermarked again enter image description here

@ZachYoung I used some different image magic, also scriptable, the point is:-

Although "What's done cannot be undone" Macbeth (Act 5.1. 63-4) is very true especially within a PDF or image. We also know and expect that it too applies to any PDF (de)constructs. Thus depending on value of a forgery it will always be worth engineering a partially reversed copy, fit for scrutiny or use, but will like the watermarked copy, still not be the original, however all the same, may look almost just as good.

The Idiom implies don't bother yourself about it. Its best not done in the first place.

The nearest to best, is use a watermark exactly the same as the text outlines, like this:-

enter image description here

K J
  • 8,045
  • 3
  • 14
  • 36