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

Adding paper source to JobTemplate #5

Open
ronnybremer opened this issue May 12, 2024 · 7 comments
Open

Adding paper source to JobTemplate #5

ronnybremer opened this issue May 12, 2024 · 7 comments

Comments

@ronnybremer
Copy link
Contributor

I am not an expert in the IPP protocol, but where would be the correct place to specify the paper source / input try to use? I would be happy to provide a PR once I know my way around.

@ronnybremer
Copy link
Contributor Author

PR #4

@sliemeobn
Copy link
Owner

good question ; )

I would assume it is specified using the media attribute as described here: https://www.rfc-editor.org/rfc/rfc8011#section-5.2.11

for quick-and-dirty "raw" support, I would assume something like this will work:

let response = try await printer.printJob(
    documentFormat: "application/pdf",
    jobAttributes: [
        .media: .init(.name(.withoutLanguage("some-media"))),
    ],
    data: .bytes(pdf)
)

But I am not sure about using name vs keyword. Also, one would probably have to first inspect the media-supported attribute for this to make sense generically.

@ronnybremer
Copy link
Contributor Author

ronnybremer commented May 12, 2024

Thank you @sliemeobn, that already works perfectly to specify the media size.

According to the RFC, a keyword is a tighter specification of a nameWithoutLanguage, so as an ad-hoc solution this would work, I will try to integrate it as keywords in a PR, but that will take a bit of time. Probably going to add a few standard paper sizes as constants, too.

For the paper source there seems to be a job template attribute, see here: IPP Javascript Lib. However, the RFC seems to have deprecated the use of "media-col". I will need to read up further on that.

For now I will try with your documented "some custom keyword" approach.

@ronnybremer
Copy link
Contributor Author

Small correction, the media-col does not seem to be deprecated but rather an option for the printer to implement.

A Printer MAY support the "media" attribute without supporting the "media-col" attribute. However, if a Printer supports the "media-col" attribute, it MUST also support the "media" attribute.

@ronnybremer
Copy link
Contributor Author

ronnybremer commented May 12, 2024

As a working example I am using this code and it seems to work:

        // A6, Bypass Tray
        jobAttributes["media-col"] = .init(.collection([
            "media-size" : .init(.collection(["x-dimension" : .init(.integer(105 * 100)),
                                              "y-dimension" : .init(.integer(148 * 100))
                                             ])),
            "media-source" : .init(.keyword("by-pass-tray"))
        ]))

This is printer specific, the by-pass-tray was taken from the media-source-supported of the printer attributes.

@sliemeobn
Copy link
Owner

cool to see, thanks for sharing!

but as this code demonstrates: it gets intricate very quickly, with many variants and asterisks (like "what does this printer support")

so, I wonder if it is at all worth the trouble trying to wrap this all in a nicely typed API 🤔

@ronnybremer
Copy link
Contributor Author

but as this code demonstrates: it gets intricate very quickly, with many variants and asterisks (like "what does this printer support")

Absolutely agree, in order to build a sophisticated application, you need to query the printer and determine the options needed/supported. However, in that case you can also use AirPrint, if supported, which will do exactly that for some options already.
However, if your application is more "industrial" and tied to a specific range of printers / use cases, you will probably get away with more fixed assumptions.

so, I wonder if it is at all worth the trouble trying to wrap this all in a nicely typed API

I would say that the majority of the options is way too vast to be included, however, a few items are very likely to be used more often, like

  • media dimensions
  • paper tray
  • output bin
  • finishing

Maybe they should be included in a more prominent way and for the rest an example code like mine above could serve as a starting point for a possible implementation.

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