Post navigation

pdf2email is a CUPS backend that uses GhostScript to print a document to PDF and sends the final file to the user that requested the print via email. This software is written in Python. I had written this backend a few months ago, it has worked fine for me, so I decided to release it. Your feedback is welcome.

pdf2email is a CUPS backend that uses GhostScript to print a document to PDF and sends the final file to the user that requested the print via email. This software is written in Python. I had written this backend a few months ago, it has worked fine for me, so I decided to release it. Your feedback is welcome.

Requirements

The following software is required so that this backend functions correctly:

Email server, on which usernames from the LAN workstations either match the users on the email server or proper mappings (aliases) have been set.

Installation

Put the “pdf2email” file in /usr/lib/cups/backend/ and set the executable bit:

chmod +x /usr/lib/cups/backend/pdf2email

Configuration

Open the script in a text editor and set a couple of settings:

1. Set the email server’s hostname:

SMTP_Server = "mail.example.org"

2. Set the email address of the sender as it will appear in the email:

print_admin = "admin@example.org"

3. (Optional) Set the path to a text file that contains PDFmarks. If you don’t know what PDFmarks are, you should leave this variable empty. (see some more info in the PDFmarks section):

pdfmarks_file = ""

Configure a CUPS Printer

This section describes in brief all the required actions in order to add a printer that uses this backend to CUPS.

Decide the printer’s name, eg “TestPDFprinter”.

Decide the directory, where the PDF files are saved temporarily. This directory must be writable by the users. Usually, /tmp is perfect for this. Note, that no PDF files are left in this directory. This piece of information is used in the Device URI of your CUPS printer. For example, provided that the /tmp directory will be used, the Device URI would be: pdf2email:/tmp

WARNING: It is your exclusive responsibility to examine the printer driver’s license prior to using the PPD file. NO PPD FILES ARE SHIPPED WITH THE pdf2email BACKEND.

Finally, add a new printer that uses this backend, either by using lpadmin from the command line or by using the web-based administration interface of CUPS or by using any other CUPS Server management software.

Using lpadmin from the shell

Using CUPS web-based interface or other software

Use the provided “Add Printer” facility. Some notes that might be useful:

In the device dropdown box, select the following:Direct PDF Printing/Delivery to user email

In the device URI box use the writable directory, eg:pdf2email:/tmp

If asked about the type of the print queue, use “RAW“.

USAGE

Make this printer available to the LAN through the IPP, SAMBA or any other protocol and add it to your printer list in your client machines. Whatever you send to that printer will be converted to a PDF document and will be emailed to your user’s email address.

Trouble?

If any error occurs during the PDF creation process, there will be a failure notice in your inbox and a message in syslog (/var/log/messages).

In case you receive no email after requesting a print, check syslog for any error messages. If there aren’t any, the check CUPS error log.

Finally, note that if you use a security layer like SELinux, then you might need to further adjust it so it lets 3rd party CUPS backends to function. This is beyond the scope of this document.

PDFmarks

If you do not know what pdfmarks are, please do a web search about them. This backend can include PDFmarks in the final PDF document. Do not expect anything spectacular, as this script cannot process the document for bookmarks, links etc. What it can do is to add pre-defined pdfmarks to all PDF documents.

For example, if, for example, you want to fill some of the document properties, save the following in a file:

License

Download

All versions of the software, including the latest stable release, are available from the development web site’s download area.

Donate

This software is released as free software. Nevertheless, its development requires time and effort. A small donation, as a sign of appreciation of the effort, is welcome. Please, use the following button to visit the Donations page. Thank you.

Support

This software is released as free software without any warranties or official support. You can still get first class support from the community of users.

About George Notaras

George Notaras is the editor of G-Loaded Journal, a technical blog about Free and Open-Source Software. George is a GNU/Linux enthusiast, a self-taught programmer and system administrator. He strongly believes that "knowledge is power" and has created this web site to share the IT knowledge and experience he has gained over the years with other people. George primarily uses CentOS and Fedora and spends some of his spare time developing open-source software.
Follow George on Twitter: @gnotaras

About

G-Loaded Journal is a technical blog that publishes news, guides and tutorials about GNU/Linux and other Free Open-Source Software. Our mission is to share our experience and knowledge about system administration, automation and programming.