The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

PostScript::PPD - Read PostScript Printer Definition files

SYNOPSIS

    use PostScript::PPD;

    my $ppd = PostScript::PPD->new( $file );

    print "Maker: ", $ppd->Manufacturer, "\n", 
          "Mode: ", $ppd->ModelName;

    # Also:
    print "Maker: ", $ppd->get( 'Manufacturer' ), "\n", 
          "Mode: ", $ppd->get( 'ModelName' );

    # Get a list of UI groups
    my @groups = $ppd->Groups;

    # Get one UI group
    my $G = $ppd->Group( $groups[0] );

    # Get a list of UI options in that group
    my @UIs = $G->UIs;
    
    # Get one UI option
    my $ui = $G->UI( $UIs[0] );

    print "Default $groups[0] $UIs[0]: ", $ui->default;

ABSTRACT

PostScript::PPD reads and parses PostScript Printer Definition files, called PPDs.

DESCRIPTION

PostScript::PPD reads and parses PostScript Printer Definition files, called PPDs.

PPDs contain key/value tuples that describe the printer, its capabilities and the printing options available. The printing options are classified as User Interface (UI) options, which are grouped into groups.

I huge database of PPDs is available from http://www.linuxfoundation.org/en/OpenPrinting/Database/Foomatic.

Schema

A PPD is a series of key/value pairs in two groups. The first group provides information about the printer and some of its features. The second group describe all the options that the PPD provides, as well as an organised UI for setting them. This UI is organised into a hierarchy :

    Group1
        Option1 
            key1: value
            key2: value
        Option2
            key1: value
            key2: value
    Group2
        OtherOption1 
            key1: value
            key2: value

A value can be a block of PostScript, to be executed on the printer, or a value to be passed to lp -o.

Very simple example:

    *OpenGroup: General/General
    *OpenUI *PageSize/Page Size: PickOne
    *OrderDependency: 100 AnySetup *PageSize
    *DefaultPageSize: Letter
    *PageSize Letter/US Letter: "<</PageSize[612 792]/ImagingBBox null>>setpagedevice"
    *CloseGroup: General

So if you wanted to use "US Letter" sized paper, you would use the following command:

    lp -o PageSize=Letter

METHODS

new

    my $ppd = PostScript::PPD->new;
    my $ppd = PostScript::PPD->new( $ppdfile );

Create the object, optionally loading $ppdfile.

load

    $ppd->load( $ppdfile );

Load a PPD file.

parse

    $ppd->parse( $text );

Parses a PPD as a string. Uses "\n" as line sepperators.

get

    my $value = $ppd->get( $name );
    my $value = $ppd->get( $name, $subkey );
    
    my $value = $ppd->$name();
    my $value = $ppd->$name( $subkey );

Returns one value from the PPD.

    my $ps = $ppd->CustomPageSize( 'True' );
    my $ps = $ppd->get( 'CustomPageSize', 'True' );

No, this doesn't set the CustomPageSize to True; it returns the PostScript needed by the printer to set CustomPageSize to True.

The value returned is a "PostScript::PPD::Subkey" object or a simple string for information keys.

AUTOLOAD

AUTOLOAD is used to implement accessor methods for all keys in the PPD.

Groups

    my @groups = $ppd->Groups;
    my $arrayref = $ppd->Groups;

Returns a list of available groups, in the order they are defined in the PPD.

Group

    my $group = $ppd->Group( $groupname );

Returns one UI option group named $groupname. An option group would be displayed as one tab in the printer configuration widget.

Syntatic sugar for

    my $group = $ppd->get( group => $groupname );

PostScript::PPD::Subkey

A PostScript::PPD::Subkey represents a group of UI options, a single UI option, or the value of one UI option key.

get

Get a key from this subkey. Itself returning either a PostScript::PPD::Subkey or a simple scalar.

AUTOLOAD

    my $text = $PageSize->Letter

Syntatic sugar for

    my $text = $PageSize->get( 'Letter' );

as_string

    print "$subkey";
    print $subkey->get('value')||$subkey;

A PPD subkey will stringies to it's value.

name

Returns the name of this UI group, option or key.

default

Get the default value for this UI option. That is, for option PageSize, returns the option PageSizeBDefault.

text

Returns the text you will want to display.

UIs

Get a list of all UI options in a group.

UI

Get a single UI option from a group.

list

Returns a list of all values for this UI option.

sorted_list

Returns a list of all values for this UI option, sort by their "text".

Dump

Handy method to dump out the object. Because Data::Dumper will print the entire PPD.

SEE ALSO

Net::CUPS

AUTHOR

Philip Gwyn, <gwyn-at-cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2008-2023 by Philip Gwyn

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.