Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set custom default page size for printer #40

Open
philomory opened this issue Oct 28, 2021 · 1 comment
Open

Set custom default page size for printer #40

philomory opened this issue Oct 28, 2021 · 1 comment

Comments

@philomory
Copy link

philomory commented Oct 28, 2021

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.

@JackJieMa
Copy link

JackJieMa commented Nov 16, 2022

I also encountered this problem when setting options, may I ask, have you made other settings take effect? For example, if I want to change the default options in ppd, it doesn't work after using cups.PPD.markOption(). Is this the case where you are?
choice = ppd.markOption('StpColorPrecision','Normal')

choice = ppd.markOption('PageSize:','w432h576-div2')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants