OpenPrinting / cups

OpenPrinting CUPS Sources
https://openprinting.github.io/cups
Apache License 2.0
1.01k stars 182 forks source link

Wishlist: shrink-to-page mode badly needed #763

Closed callegar closed 1 year ago

callegar commented 1 year ago

Hi,

I am encountering the following problem with cups:

I have a document where page 1 is slightly larger than an A4 due to the use of a legacy page format and page 2 is A5. I need to print it for paper archival so that it fits on a single A4 slice of paper, using duplex.

I cannot seem to be able to do it with current cups. Either:

Because I need duplex, I cannot work around this issue by using two separate print jobs.

I think that a shrink-to-page option is very much needed. The result should be similar to fit-to-page but with the restriction that pages can only be scaled down.

This could be implemented in two ways: with a new shrink-to-page option or maybe with a fit-to-page-mode option working together with fit-to-page.

michaelrsweet commented 1 year ago

This is the "print-scaling=auto-fit" behavior. I don't know whether all of cups-filters supports it, but that is the standard option/IPP attribute and value.

callegar commented 1 year ago

@michaelrsweet

This is the "print-scaling=auto-fit" behavior. I don't know whether all of cups-filters supports it, but that is the standard option/IPP attribute and value.

Is this meant to be used from the CLI as in lp -d <printer> -o print-scaling=auto-fit <file.pdf>?

If so, unfortunately the -o print-scaling=auto-fit does not seem to do that (or is buggy). This either in conjuction with ipp-attribute-fidelity=false or ipp-attribute-fidelity=true

My feeling is that the option is there (see also bug #108), but does not work in in the way I need.

Both auto-fit and auto-fill do either scale down or up in order to adjust the content to the page (fit assuring that no crop happens, fill with no such warranty). Adding ipp-attribute-fidelity=false in conjunction to auto-fit or auto-fill should ensure that if the content is already smaller than the printable area there is no scaling.

However, the choice whether to scale or not seems to be done at the document level not at the page level, which makes it totally useless in my case. Namely, if you need to scale the first page (because the content is too big) then all pages will be scaled to fit or fill the media, regardless of the fact that in some pages the content might be much smaller than the media size and that ipp-attribute-fidelity=false is selected to avoid expanding small contents to the media size.

Now I wonder if I should modify this bug to ask that the scaling options can be applied on a page by page basis. Can this be considered? In the end the old acrobat reader for linux had an option doing this right before it was retired.

michaelrsweet commented 1 year ago

There is no "auto-fill" value. The defined values (and their semantics) from PWG 5100.13-2023: IPP Driver Replacement Extensions v2.0 (NODRIVER) are:

What you want is 'auto-fit', which is applied per-page. But if cups-filters isn't implementing it correctly, please file a bug over there.

callegar commented 1 year ago

There is no "auto-fill" value

sorry, I meant just auto

What you want is 'auto-fit', which is applied per-page.

OK, so my issue is that it is not. I'll file a bug for it after building a test case. Before that, and to make sure that I file the bug correctly, is this driver dependent? Is the issue possibly tied to a specific driver (e.g., hplip) or likely to be in a generic filter?

Before I forget: thanks for all the explanations, I know they take time

michaelrsweet commented 1 year ago

No, it isn't driver dependent, just the core filters that need to support it so the drivers get the data properly scaled for them.

zdohnal commented 1 year ago

@michaelrsweet since print-scaling is IPP attribute reported by IPP printer, shouldn't the printer firmware be able to do the trick, so it would be firmware dependent?

Either way, pdftopdf seems to support it (libcupsfilters - cupsfilters/pdftopdf/pdftopdf.cxx):

 560   if (printer_attrs == NULL && !param.pagesize_requested &&
 561       param.booklet == CF_PDFTOPDF_BOOKLET_OFF &&
 562       param.nup.nupX == 1 && param.nup.nupY && 1)
 563     // With no printer capability info and, no given page size, and no
 564     // requirement of all pages being the same size just use the input page sizes
 565     param.cropfit = true;
 566   else if ((val = cupsGetOption("print-scaling", num_options, options)) != NULL)
 567   {
 568     // Standard IPP attribute
 569     if (!strcasecmp(val, "auto"))
 570       param.autoprint = true;
 571     else if (!strcasecmp(val, "auto-fit"))
 572       param.autofit = true;
 573     else if (!strcasecmp(val, "fill"))
 574       param.fillprint = true;
 575     else if (!strcasecmp(val, "fit"))
 576       param.fitplot = true;
 577     else if (!strcasecmp(val, "none"))
 578       param.cropfit = true;
 579     else
 580       param.autoprint = true;

@callegar can you enable debug logging by cupsctl LogLevel=debug2 and attach the /var/log/cups/error_log here as a file?

michaelrsweet commented 1 year ago

@zdohnal "print-scaling" is indeed reported by the printer, but for streaming raster formats (PWG or Apple raster), the Client is responsible for scaling the input document. Also, whenever we convert from one format to another (even to PDF), we need to apply the scaling since at that point we don't send the print-scaling option to the printer (because filtered output is assumed to have all of those options applied...)