Search code examples
bashapplescriptpdftk

How do I pipe pdf-generating output through pdftk to remove annotations?


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

Solution

  • 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.