Utiliser un script en tant qu’imprimante pour traiter la sortie (PDF)

J’aimerais append une imprimante “virtuelle” pour envoyer facilement des fichiers PDF à partir de n’importe quel logiciel. L’imprimante doit être un script qui traite ensuite la sortie PDF. Le cas d’utilisation peut être “impression sur stockage en nuage” ou “impression sur archive”, etc.

Les possibilités que j’ai découvertes jusqu’ici sont:

  • Le backend du tube CUPS ( décrit ici ) qui semble ne pas être disponible sur Ubuntu
  • tea4cups ( de ce fil ) qui transfère le fichier à lp après le pré-traitement. Mais je ne veux pas réellement l’imprimer.

Existe-t-il un autre moyen plus simple de simplement transférer le PDF dans un script bash personnalisé?

Les indices semblent être dans le premier lien de votre question. La recherche indique que les moteurs ne sont que des scripts. Vous pouvez donc simplement écrire le vôtre. Cependant, il semble que le script que vous recherchez et qui est disponible pour OpenSuse soit décrit dans votre premier lien.

Le paquetage openSUSE RPM cups-backends fournit le script bash / usr / lib / cups / backend / pipe, qui est un back-end pour l’impression dans un programme quelconque.

Trouver ce script est compliqué par le fait qu’OpenSuse utilise maintenant les installateurs .ymp en un clic et que vous devez creuser un peu plus pour trouver le fichier .rpm contenant le script. Voici un exemple tiré directement de cups-backends-1.1-296.6.noarch.rpm disponible ici.

L’ouverture du package avec le rouleau de fichiers et la navigation vers /./usr/lib/cups/backend/ dans le package et l’ouverture du pipe révèlent le script ci-dessous:

 #! /bin/bash # CUPS wrapper backend "pipe" for printing to any program. # It forwards the print job data like a pipe into another command. # Author: Johannes Meixner , 2009, 2014 # For basic information see "man 7 backend" and "man 7 filter". # This program is free software; you can redissortingbute it and/or modify it # under the terms of the GNU GENERAL PUBLIC LICENSE Version 2 # as published by the Free Software Foundation. # Activate the "set -x" line to get debugging info in /var/log/cups/error_log: #set -x # Output "Device Discovery" information on stdout: if test "$#" = "0" then echo 'direct pipe "Unknown" "Forward print job data like a pipe to another command"' exit 0 fi # Output usage information in case of wrong number of parameters: if test "$#" != "5" -a "$#" != "6" then echo 'Usage: pipe job-id user title copies options [file]' 1>&2 echo 'Queue setup example:' 1>&2 echo 'lpadmin -p queue_name -v "pipe:/path/to/command?option1=value1&-option2&value2" -E' 1>&2 echo 'The command is called with the specified options as:' 1>&2 echo '/path/to/command option1=value1 -option2 value2' 1>&2 echo 'The original command line parameters (... job-id user ...)' 1>&2 echo 'are provided as environment variables PIPE_BACKEND_ARGV[0-6]' 1>&2 exit 1 fi # Keep the original command line parameters (... job-id user ...) # in environment variables to make them available for the command: export PIPE_BACKEND_ARGV0="$0" export PIPE_BACKEND_ARGV1="$1" export PIPE_BACKEND_ARGV2="$2" export PIPE_BACKEND_ARGV3="$3" export PIPE_BACKEND_ARGV4="$4" export PIPE_BACKEND_ARGV5="$5" export PIPE_BACKEND_ARGV6="$6" # Have the input at fd0 (stdin) in any case: if test -n "$6" then exec <"$6" fi # To be on the safe side clip anything after the first space character # because spaces are excluded characters in a URI (see RFC 2396): URI=${DEVICE_URI%% *} # Extract the command to which the job schould be sent from the URI. # Clip the URI scheme (anything up to the first ':' character) and # clip anything after the first '?' character # because anything after the first '?' character are options: COMMAND=${URI#*:} COMMAND=${COMMAND%%\?*} # Extract the options (eg from 'pipe:/path/to/command?option1=value1&-option2&value2' # clip anything up to the first '?' character and # replace the options separator '&' character by a space: OPTIONS=${URI#*\?} if test "$OPTIONS" = "$URI" then OPTIONS="" fi OPTIONS=$( echo "$OPTIONS" | tr '&' ' ' ) # Options could have been specified in a wrong way # as addendum to the DeviceURI separated by spaces # (spaces are excluded characters in a URI, see RFC 2396) # which works by luck at least for some CUPS versions # see https://bugzilla.novell.com/show_bug.cgi?id=499735 # like 'pipe:/path/to/command option1=value1 -option2 value2' # nevertheless use additionally those kind of options too: MORE_OPTIONS=${DEVICE_URI#* } if test "$MORE_OPTIONS" = "$DEVICE_URI" then MORE_OPTIONS="" fi OPTIONS=$( echo "$OPTIONS" "$MORE_OPTIONS" | tr -s ' ' ) # Test if the command is executable: if ! test -x "$COMMAND" then echo "Cannot execute $COMMAND" 1>&2 exit 1 fi # Replace this wrapper with the actual command # so that it exits with the exit code of the command # and that the command gets any signals directly. exec "$COMMAND" $OPTIONS 

Comme il s’agit d’un script bash, vous devriez pouvoir l’utiliser avec n’importe quelle version de ‘nix, y compris Ubuntu, avec un shell bash, pas seulement Suse.

Pour append un backend aux cups, vous devez le copier dans /usr/lib/cups/backend et définir les permissions et les droits de propriété correspondants.

chown root:root /usr/lib/cups/backend/pipe

chmod 755 /usr/lib/cups/backend/pipe

Sources:

https://www.cups.org/doc/man-backend.html

https://build.opensuse.org/package/view_file/Printing/cups-backends/cups-backends.spec?expand=1

Comment extraire un fichier RPM?