[cups.general] develop custom text-only driver

Michael Sweet msweet at apple.com
Mon Apr 26 08:59:14 PDT 2010


On Apr 26, 2010, at 2:58 AM, David wrote:
> Hi,
> 
> I would like to develop a custom text-only printer driver. The CUPS manuals are not much detailed on this, can somebody advice any other helpful documents on this?

There isn't a lot of information for this since most people just use interface scripts and almost never print from regular applications since they usually only produce PS or PDF.

> What I would like to do:
> I have a system that generates plain-text print jobs that need to be passed through to the printer.
> 
> However within the "header" part of the my print job (first few commands) I would like to pass some printer configuration values, for example Page Size or Orientation or Resolution.
> 
> So my custom driver would have to offer a few Configuration Options in the Printer setup page (web-interface) and then do a little text processing in the filter.

What you can do it provide a PPD file with the options you want, but in the PPD file you will only list a filter for "text/plain" and any other text file types you care about:

    *cupsFilter: "text/plain 0 /path/to/your/filter"

Your filter will need to look at argv[5] to get the options that were selected and merge them with the defaults from the PPD file; for a C-based filter you can use:

    int num_options;
    cups_option_t *options;
    ppd_file_t *ppd;
    ppd_choice_t *choice;

    num_options = cupsParseOptions(argv[5], 0, &options);
    ppd         = ppdOpenFile(getenv("PPD"));

    ppdMarkDefaults(ppd);
    cupsMarkOptions(ppd, num_options, options);

    ...

    choice = ppdFindMarkedChoice(ppd, "YourOptionName");

This is the same as a PS or raster driver, just you'll only accept plain text instead of raster or PostScript...

________________________________________________________________________
Michael Sweet, Senior Printing System Engineer, PWG Chair








More information about the cups mailing list