Skip to content

Instantly share code, notes, and snippets.

@sandipb
Last active May 5, 2022 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sandipb/b1a773356d38556618101a53d6468f99 to your computer and use it in GitHub Desktop.
Save sandipb/b1a773356d38556618101a53d6468f99 to your computer and use it in GitHub Desktop.
Fix cups-pdf not printing PDFs with restrictions

Fix problem when cups-pdf (actually Ghostscript) refuses to print PDF files with restrictions

Specifically, even if the file has no printing restrictions, like many government forms do (my specific itch), Ghostscript refuses to print the file and generates a blank pdf.

Steps to fix

  1. Put contents of unblockprint.sh in an executable file named /usr/lib/cups/filter/unblockprint. Make sure that the permissions of this file matches others in the same directory.
  2. Put local.convs in /etc/cups
  3. Restart cups service.
application/postscript application/vnd.cups-postscript 60 unblockprint
#!/bin/sh
#
# unblockprint - Removes comment blocking PDF printing
echo "DEBUG: unblockprint argv[$#] = $@" >&2
if [ $# -lt 5 -o $# -gt 6 ]; then
echo "ERROR: $0 job-id user title copies options [file]" >&2
exit 1
fi
# Read from given file.
if [ -n "$6" ]; then
exec <"$6"
fi
sed -e '/eleven lines/,+11d' | $CUPS_SERVERBIN/filter/pstops "$1" "$2" "$3" "$4" "$5"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment