Skip to content

Set custom default page size for printer #40

@philomory

Description

@philomory

In the CUPS user interface, you can set a custom paper size by selecting "Custom" for the media size, which adds fields for width and height, and a drop-down for units. When you submit the page, this results in a POST to the /admin endpoint with an OP of set-printer-options, a PageSize of Custom, and fields PageSize.Width, PageSize.Height, and PageSize.Units set to the values you had specified.

The way to customize printer defaults in PyCups seems to be a bit different. You can use cups.Connection.getServerPPD() to fetch a printer PPD, cups.PPD() to instantiate it as an object within Python, call e.g. ppd.setOption('PageSize','w432h576') to select the desired page size, and then pass that PPD object to cups.Connection.addPrinter() to add a new printer with adjusted options. Unfortunately, this doesn't work for custom page sizes; PageSize.Width, PageSize.Height and PageSize.Units don't seem to have any effect when used with cups.PPD.markOption(), and setting PageSize to e.g. Custom.576x432pt (the value that gets stored in the actual PPD for PageSize when you configure things via the CUPS UI) doesn't work either, you end up with the page size set to just Custom, with no actual width or height set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions