OpenPrinting CUPS Filters

repository·master·Indexed 41 days ago

https://github.com/openprinting/cups-filters

Backends and filters for the Common Unix Printing System (CUPS) that enable PDF-centric and driverless (IPP Everywhere) printing workflows. Designed for CUPS 2.2.2 or newer, it provides support for PWG Raster, Apple Raster, PCLm, and PDF output formats, and includes specific filters such as imagetopdf and pdftopdf.

Tokens
6.9K
Snippets
13
Records
29
Agent score
2%

What's inside CUPS Filters

  1. Overview of OpenPrinting CUPS Filters

    master

    OpenPrinting CUPS Filters is a package containing backends, filters, and software that provides essential functionality for the CUPS (Common Unix Printing System) printing system. It retro-fits the filter functions of libcupsfilters and libppd to CUPS 2.x.

    Key features include:

    • Support for driverless printing (IPP Everywhere, AirPrint, Wi-Fi Direct).
    • Support for various output formats including PWG Raster, Apple Raster, PCLm, and PDF.
    • Integration with PDF-centric printing workflows.

    Compatibility Note:

    • This version (2.x) is designed for CUPS 2.2.2 or newer.
    • For older CUPS versions, use the cups-filters 1.x line.
    • CUPS 3.x uses a new all-IPP architecture that does not use external filters and therefore does not require this package.
  2. Use foomatic-hash to secure foomatic-rip filters

    master

    To prevent security exploits involving malicious PPD options (like FoomaticRIPCommandLine), the foomatic-rip filter now requires administrative approval of command values via the foomatic-hash tool.

    Workflow:

    1. Run foomatic-hash on a PPD file or a directory of drivers. This generates two files: one with found values for review, and one with unique hashes.
    2. Review the found values to ensure they are correct.
    3. Move the file containing the approved hashes into /etc/foomatic/hashes.d/.

    Search Paths for Hashes:

    • /etc/foomatic/hashes.d: For hashes allowed by the local administrator.
    • /usr/share/foomatic/hashes.d: For hashes provided by printer driver projects.
  3. Use JCL for native PDF printers

    master

    For modern native PDF printers controlled via IPP, pdftopdf can emit Job Control Language (JCL) when the provided PPD file contains the *JCLToPDFInterpreter: keyword. This enables hardware-level features like device collation or hardware copy generation.

    PPD Configuration Example:

    *JCLBegin:           "<1B>%-12345X@PJL JOB<0A>"
        *JCLToPDFInterpreter: "@PJL ENTER LANGUAGE = PDF <0A>"
        *JCLEnd:             "<1B>%-12345X@PJL EOJ <0A><1B>%-12345X"

    Key Features:

    • Custom JCL Strings: For any marked option in the PPD, you can use the prefix pdftopdfJCL<option name> to send raw JCL strings. This includes *pdftopdfJCLBegin and *pdftopdfJCLCopies.
    • Copies Support: If the PPD contains the Copies keyword, pdftopdf automatically adds @PJL SET COPIES=... or @PJL SET QTY=....
    • UI Injection: Other JCL code can be injected using *JCLOpenUI: ... and *JCLCloseUI: ....
  4. Understand CUPS Filters versioning

    master

    CUPS Filters follows Semantic Versioning (MAJOR.MINOR.PATCH):

    • Major: Large design changes or backwards-incompatible changes to the CUPS Filters API.
    • Minor: New features and smaller changes that are backwards-compatible.
    • Patch: Bug fixes.

    Compatibility Definitions:

    • Binary compatibility: For public APIs.
    • Output format compatibility: For program interfaces.

    Release Types:

    • Feature Release: The first production release in a series (e.g., 1.1.0). Only these may contain new features.
    • Beta-test: Appends b and a number (e.g., 2.2b1).
    • Release Candidate: Appends rc and a number (e.g., 2.2rc1).
  5. Coding guidelines for source files and comments

    master

    When contributing source code, follow these file and comment standards:

    Source Files

    • Naming: Use lowercase ASCII letters, numbers, dashes (-), underscores (_), and periods (.).
    • Extensions:
      • .c for C files.
      • .cxx for C++ files.
      • .h for include files.
    • Header: Every file must start with a header containing the file purpose, copyright, and license notice.

    Comments

    • Use block comments (/* ... */) to describe operations performed by a group of statements. Block comments are preferred for multi-line comments.
    • Avoid per-line comments unless necessary; refactor code instead.
    • Comments are used by codedoc to auto-generate documentation.
    /*
     * Description of file contents.
     *
     * Copyright © 2021-2022 by OpenPrinting
     *
     * Licensed under Apache License v2.0.  See the file "LICENSE" for more
     * information.
     */
  6. Prerequisites for compiling and using cups-filters

    master

    To compile and use cups-filters, ensure the following dependencies are met:

    Core Dependencies:

    • CUPS (version 2.2.2 or newer)
    • libcupsfilters 2.x
    • libppd

    Recommended PDF Renderers (at least one required, especially for non-PDF printers):

    • Ghostscript (preferred)
    • Poppler
    • MuPDF (version 1.15 or newer is required to avoid printing bugs)

    Build Tools:

    • gcc (C compiler)
    • automake
    • autoconf
    • autopoint
    • libtool
    • On Debian/Ubuntu-based systems, installing the build-essential package will satisfy most build tool requirements.

    Ghostscript Specific Requirements: If using Ghostscript (via gsto... or universal filters), you must use Ghostscript 10.00.0 (10.01.0+ highly recommended). It must be built with libcups (2.2.2+) and include the following output devices:

    • pdfwrite
    • ps2write
    • cups
    • pwgraster
    • appleraster
    • pclm
    • pclm8
    • pdfimage24
    • pdfimage8
    • pxlcolor
    • pxlmono
  7. Use the BEH backend wrapper for configurable error handling

    master

    The beh (Backend Error Handler) is a wrapper for CUPS backends that prevents print queues from being disabled when a backend error occurs (e.g., printer offline). It allows you to configure retry logic, intervals, and whether to disable the queue upon final failure.

    Activation

    Activate beh for a print queue using lpadmin with a specific URI format:

    lpadmin -p <queue name> -E -v beh:/<dd>/<att>/<delay>/<originaluri>

    URI Parameters

    All parameters must be specified, even if they are effectively ignored by other settings:

    • <dd> (Don't Disable): 1 means the queue is never disabled (even if the job is lost); 0 means the error status is passed to CUPS, which may disable the queue.
    • <att> (Attempts): Number of retries. 0 means infinite retries.
    • <delay> (Delay): Integer number of seconds between attempts. (Meaningless if <att> is 1).
    • <originaluri>: The original backend URI (find this via lpstat -v).

    Note: beh works with all backends except the HPLIP hp backend.

    Usage Examples

    • Retry 3 times with 5s delay, then discard job (don't disable queue): beh:/1/3/5/socket://printer:9100
    • Retry 10 times with 60s delay, then disable queue on failure: beh:/0/10/60/socket://printer:9100
    • Retry infinitely with 60s delay (ideal for home/desktop printers): beh:/1/0/60/usb://Brother/HL-5040%20series
    lpadmin -p <queue name> -E -v beh:/<dd>/<att>/<delay>/<originaluri>
  8. Set up a Generic Text-Only Printer with texttotext

    master

    The texttotext filter is designed for text-only printers (line printers, daisy-wheels, POS printers). It takes UTF-8 plain text as input and avoids the overhead of PDF conversion.

    Installation: To set up a printer using this filter, use lpadmin with the following driver:

    # Use the textonly.ppd driver
    # Note: This is a conceptual command based on the documentation
    # lpadmin -p <printer_name> -m drv:///cupsfilters.drv/textonly.ppd

    Configuration via Installable Options:

    • Page Sizes: Define the number of lines and columns for each supported page size. (Default: 6 lines per inch, 10 columns per inch).
    • Form Feed: Configure whether to send a Form Feed character after each page. It is highly recommended for sheet alignment. If the printer doesn't support it, disable it and ensure line counts are adjusted so the printer advances via blank lines.

    Key Features:

    • Continuous Printing: Supports a non-paginated mode for roll paper (POS printing) that ignores page height.
    • Pagination Control: Supports standard CUPS options like page-ranges, page-set, output-order, collate, and multiple copies when pagination is enabled.
  9. Debug PostScript printer errors with psdebug

    master

    If a PostScript printer misbehaves or crashes due to Ghostscript's compressed output, you can use the psdebug option to generate uncompressed PostScript for analysis.

    Enable for a single job:

    lpr -P <printer> -o psdebug <file>
    # OR
    lp -d <printer> -o psdebug <file>

    Set as a personal default:

    lpoptions -p <printer> -o psdebug

    How to extract the output for analysis:

    1. Enable file device printing: cupsctl FileDevice=yes
    2. Create a test queue that prints to a file:
      lpadmin -p test -E -v file:/tmp/printout -P /etc/cups/ppd/<original_ppd_name>.ppd
    3. Print to the test queue using the psdebug option.
    4. The uncompressed PostScript will be available in /tmp/printout.
    lpr -P <printer> -o psdebug <file>
    
    # To extract output for analysis:
    cupsctl FileDevice=yes
    lpadmin -p test -E -v file:/tmp/printout -P /etc/cups/ppd/<name of original queue>.ppd
  10. Coding guidelines for indentation and spacing

    master

    Follow these formatting rules for C/C++ code:

    Indentation

    • Brackets: The opening brace { must begin on a new line. The code following it starts on a new line and is indented 2 spaces. The closing brace } is placed on a new line at the original indentation level.
    • Control Flow: Single-line statements following do, else, for, if, and while are indented 2 spaces.
    • Switch Blocks: Code inside case or default blocks is indented 4 spaces.

    Spacing

    • A space must follow reserved words like if or while.
    • Do not insert a space between a function name and the arguments in parenthesis.

    Return Values

    • Parenthesis must surround returned values: return (VALUE);
    {
      int i;
    
      for (i = 0; i < 1000; i ++)
      {
        do_this(i);
        do_that(i);
      }
    }
    
    switch (array[i])
    {
      case STATE_IDLE :
          do_this(i);
          break;
    
      default :
          do_nothing(i);
          break;
    }