1

I want to pipe pdf-generating output through pdftk to remove annotations.

How can I combine this existing portion of a working AppleScript line:

do shell script "/usr/local/bin/$pdf-generating-app --page-size=A4 --page-margin=5mm " & (quoted form of POSIX path of filename) & " -o " & (quoted form of POSIX path of outputFilename)

And have that piped through pdftk to remove annotations, as per this script by Farid Cheraghi?

sh pdftk in.pdf output - uncompress | sed '/^\/Annots/d' | pdftk - output out.pdf compress
John
  • 49
  • 6
  • If you find Prince useful, please consider purchasing a license! We rely on the support of our customers to allow us to continue working on Prince in the future. If you need a license for non-commercial or academic use, just contact us. – Michael Day Jun 10 '21 at 08:17
  • I've edited my question to be less-specific. For what it's worth, I'm just a hobbyist and I need to remove the annotation to make another part of my workflow work (populating PDF annotations in Finder comments). Visually, the symbol is not obstructive and is actually nice-looking. – John Jun 11 '21 at 09:55

2 Answers2

1

Here is the final version, mostly compiled by Zilog80, that is working for me:

do shell script "/usr/local/bin/$pdf-generating-app --page-size=A4 --page-margin=5mm " & (quoted form of POSIX path of filename) & " -o - | /usr/local/bin/pdftk - output - uncompress | sed '/^\\/Annots/d' | /usr/local/bin/pdftk - output " & (quoted form of POSIX path of outputFilename) & " compress"

John
  • 49
  • 6
0

If it's YeLogic prince, you can use the hyphen (-) to make it output to stdoutand thus pipe it to pdftk :

/usr/local/bin/prince --page-size=A4 --page-margin=5mm <your filename> -o - | \
pdftk - output - uncompress | sed '/^\/Annots/d' | pdftk - output out.pdf compress

With AppleScript, that should be :

do shell script "/usr/local/bin/prince --page-size=A4 --page-margin=5mm " & (quoted form of POSIX path of filename) & " -o - | pdftk - output - uncompress | sed '/^\/Annots/d' | pdftk - output " & (quoted form of POSIX path of outputFilename) & " compress"

Anyway, i suggest you to remove the watermark directly with prince, it should be possible through CSS properties.

Zilog80
  • 2,534
  • 2
  • 15
  • 20
  • Yes, this did it. Thank you for the explanation and the solution. So that the AppleScript would compile, I needed to add a backslash in the sed portion: `| sed '/^\\/Annots/d' |` I also neglected to include my full path to pdftk in my request. – John May 10 '21 at 22:49
  • 1
    Re. removing the watermark directly, I'm using the free version of PrinceXML. According to their website, the watermark cannot be disabled on the free version. – John May 10 '21 at 22:58