这是通过 CUPS 获取纸张大小的最佳方法吗?

发布于 2024-08-26 02:27:51 字数 626 浏览 6 评论 0原文

我有一个 CUPS 作业控制文件(可以在 /var/spool/cups/cnnnnn 找到)。我需要获得所制作印刷品的实际尺寸。

这是我想出的方法:

  1. 使用 media 属性获取论文名称。 (例如Letter
  2. printer-uri 属性获取打印机uri。 (例如 ipp://localhost/printers/MyPrinter
  3. 通过将打印机 uri 传递给 IPP_GET_PRINTER_ATTRIBUTES 操作并获取 printer-name 来获取打印机名称代码>属性。 (例如MyPrinter
  4. 获取PPD 的路径,将打印机名称传递给cupsGetPPD 方法。
  5. 打开 PPD,将 PPD 的路径传递给 ppdOpenFile 方法。
  6. 通过将 PPD 和纸张名称传递给 ppdPageSize 方法来获取纸张尺寸。

这会起作用,但似乎有点迂回。有没有更有效的方式来获取我需要的东西?

I've got a CUPS job control file (these can be found at /var/spool/cups/cnnnnn). I need to get the actual dimensions of the print that was made.

This is the way I've figured out to do it:

  1. Get the paper name using the media attribute. (e.g. Letter)
  2. Get the printer uri from the printer-uri attribute. (e.g. ipp://localhost/printers/MyPrinter)
  3. Get the printer name by passing the printer uri to the IPP_GET_PRINTER_ATTRIBUTES operation and getting the printer-name attribute. (e.g. MyPrinter)
  4. Get the path to the PPD passing the printer name to the the cupsGetPPD method.
  5. Open the PPD passing the path to the PPD to the ppdOpenFile method.
  6. Get the paper size by passing the PPD and paper name to the ppdPageSize method.

This will work, but it seems a bit roundabout. Is there a more efficient way of getting what I need?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独﹏钓一江月 2024-09-02 02:27:51

作业控制文件将包含用于打印的文件的所有作业选项。有 3 种类型的作业选项:

  1. 由用户在命令行上或通过单击某些 GUI 元素(这些将出现在控制文件中)专门明确选择的作业选项;
  2. 隐式设置的,因为它们包含在特定于用户的 ~/.lpoptions 或系统范围的 /etc/cups/lpoptions 文件(用户在较新版本的 CUPS 中,特定文件已迁移到 ~/.cups/lpoptions(这些文件也将出现在控制文件中);
  3. 这些文件是 CUPS 通过解析 PPD 并查找而添加的 ;其中包含的默认设置(这些设置不会出现在控制文件中,因为 CUPS 仅在处理作业时评估它们——这可能是 2 天的时间)未来,如果您使用 -o job-hold-until=indefinite

如果您知道 printqueuename 和使用的 cupsserver,则可以使用这两个命令查询该组合的默认队列设置:

lpoptions -h cupsserver \
          -U username \
          -d printqueuename

这将返回所有内容。 (.)loptions 文件中注明的当前设置。

lpoptions -h cupsserver \
          -U username \
          -d printqueuename \
          -l

这将返回 PPD 中包含的所有用户可选设置。请注意星号 * 如何标记默认设置。每个选项的设置。另请注意,-U username 在这里很重要 - 不同的用户可能使用不同的默认设置...

现在请注意这些命令的结果,注意所使用的 PageSize。 。

The job control file will contain all the job options of the file used for printing. There are 3 types of job options:

  1. ones which were specifically and explicitely selected by the user on the commandline or by clicking some GUI elements (these ones will appear in the control files);
  2. ones which were implicitely set because they are contained in and read from a user-specific ~/.lpoptions or a system-wide /etc/cups/lpoptions file (the user specific file has been migrated to ~/.cups/lpoptions in more recent versions of CUPS (these ones will also appear in the control files);
  3. ones which were added by CUPS by parsing the PPD and looking for default settings contained there (these ones will not appear in the control files, since CUPS only evaluates them in the moment the job is processed -- which may be 2 days in the future if you used -o job-hold-until=indefinite.

If you know the printqueuename and the cupsserver used, you can query the default queue settings for that combo with these two commands:

lpoptions -h cupsserver \
          -U username \
          -d printqueuename

This will return all current settings as noted in the (.)loptions file(s).

lpoptions -h cupsserver \
          -U username \
          -d printqueuename \
          -l

This will return all user-selectable settings contained in the PPD. Note how the asterisks * marks the default setting for each option. Also note that -U username is significant here -- different users may use different default settings...

Now watch out for the results of these commands noting the PageSize used...

西瑶 2024-09-02 02:27:51

实际上,您可以使用 CUPS_GET_PPD 请求直接获取 ppd,而不是执行步骤 3 和 4。这似乎更有效。

You can actually use the CUPS_GET_PPD request to get the ppd directly instead of steps 3 and 4. This seems more efficient.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文