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

lp -o page-set=even prints an extra blank page #541

Closed
olivluca opened this issue Sep 13, 2023 · 16 comments
Closed

lp -o page-set=even prints an extra blank page #541

olivluca opened this issue Sep 13, 2023 · 16 comments

Comments

@olivluca
Copy link

I'm using my forked manual_duplex_linux repository to print in manual duplex mode: it first print the odd pages then the even ones (in reverse order and rotated 180º to cater to the paper flow in my printer), so the option are -o page-set=even -o collate=true -o outputorder=reverse -o orientation-requested=6
When the document has an odd number of pages, everything is fine, but if it has an even number of pages, an extra blank page is printed which messes up the order.
If I run the pdftopdf filter with those same parameters, no extra blank page is generated, so I don't know where that extra page comes from.
For the time being, I use pdftk to filter and rotate the even pages if the number of pages is even and lp just print them in reverse order.
This is on debian 12 with cups-filters 1.28-17-3, but I have the same problem on another computer still running ubuntu 18.

@tillkamppeter
Copy link
Member

Could you attach the PPD file of your print queue (from /etc/cups/ppd/)? Please rename it to have the name extension .txt so that GitHub accepts it.

@olivluca
Copy link
Author

Sure, here it is
Manual_Duplexer_Pantum_M6500W_series_4CF883.txt

This is another one using a virtual pdf printer (so I don't waste paper while doing tests)
Manual_Duplexer_PDF.txt

@kerneis
Copy link

kerneis commented Jan 2, 2024

For the record, I face the exact same issue using only the regular GUI printing interface. I'm printing to a USB Canon MF4700 (auto-detected by CUPS), and if I select "pages: odd" and "output order: reverse" in the print menu for a 10-page document, I end up with 6 printed sheets, the first one being blank. I have no issue when I select "pages: even" so my workaround for now is to start printing the odd pages (reversed), remove the extra blank page, and then feed back the result to the printer for the even pages — but it's annoying and can waste a lot of paper if I forget doing it.

I'd be happy to provide more information if you let me know what you need.

It looks like at least one other person faced the issue here: https://access.redhat.com/solutions/76333 but I don't have subscription so cannot read the solution they ended up with.

@ValdikSS
Copy link

ValdikSS commented Jan 3, 2025

I can confirm this, and this is reproducible with cups-pdf.
Printing even pages in reverse of 18 pages PDF file results in 10 pages of cups-pdf printout, not 9 as it should be.

@ValdikSS
Copy link

ValdikSS commented Jan 3, 2025

This one.

if ((param.evenDuplex || !param.oddPages) && (outputno & 1)) {
// need to output empty page to not confuse duplex
proc.add_page(proc.new_page(param.page.width,param.page.height),param.reverse);

@ValdikSS
Copy link

ValdikSS commented Jan 3, 2025

Right now the logic is completely broken (duplex option is not set):

Doc w/pages pdftopdf odd pdftopdf even pdftopdf even reverse
6 page 1-3-5 page 2-4-6-blank page blank-6-4-2
5 page 1-3-5 page 2-4 page 4-2
commands
/usr/lib/cups/filter/pdftopdf 1 1 1 1 'page-set=odd PageSize=A4 pdf-filter-page-logging=yes' page6.pdf  > out.pdf
/usr/lib/cups/filter/pdftopdf 1 1 1 1 'page-set=even PageSize=A4 pdf-filter-page-logging=yes' page6.pdf  > out.pdf
/usr/lib/cups/filter/pdftopdf 1 1 1 1 'page-set=even OutputOrder=Reverse PageSize=A4 pdf-filter-page-logging=yes' page6.pdf  > out.pdf

If we invert the logic in (outputno & 1) check, it would work as expected for the manual duplex scenario (where you do not enable duplex option, as the printer doesn't support it).

However, this is also flawed. If I want just to print, say, the even pages of document in reverse, and not doing manual duplex, I will get first blank page in this scenario.

@tillkamppeter, that was your change in 686a28d regarding Setting page-set=even and duplex=none results in filter failure.

I know it's dumb, but I see this issue occurring from time to time, mostly because PDF readers remember print settings and people don't notice when printing one-page documents that they have "Print only even pages" option set.

Basically, if you're printing a one-page document, and your pdftops renderer is eiher pdftops or pdftocairo, printing will fail because page-set=even means you need to print page #2, and you only have one page.

I have fixed this by fixing the behavior of manual duplex. Usually, you print the odd pages, then put them back into the input tray and print the even pages. If the document has an odd number of pages, there is one odd page more than even pages, meaning that when you printed the even pages before, the last odd page stayed in the input tray. Now I let the pdftopdf filter add a blank page when printing the even pages of a document with an odd number of pages, this way pulling the last odd page out of the input tray. This also has the side effect that the even page set is never empty also with a document of only one page, preventing this error. And automated processes (like GUIs) applying manual duplex, work also with one-page documents.

The change is in cups-filters 1.0.55 which I have released today. It will soon appear in Utopic.

What do you think?
FYI, right now pdftopdf generates incorrect PDF which could not be opened when printing 1-page document with page-set=even.

ValdikSS added a commit to ValdikSS/cups-filters that referenced this issue Jan 3, 2025
…nting#541)

Since commit 686a28d pdftopdf started to insert extra blank page
when printing even-paged documents in page-set=even mode.
This was the attempt to fix two issues at once:

* [Print 1-page documents in even mode][1]
* Treat non-duplex even reverse printing as second step of manual duplex

Unfortunately due to inverted logic this didn't fix any issues
and introduced new one, outlined above.

This code fixes printing 1-page documents in even mode, and prints
exactly what the user requested in even mode for larger documents,
without inserting extra blank pages.

[1]: https://bugs.launchpad.net/ubuntu/+source/cups-filters/+bug/1340435
ValdikSS added a commit to ValdikSS/libcupsfilters that referenced this issue Jan 3, 2025
Since [commit 686a28d][2] pdftopdf started to insert extra blank page
when printing even-paged documents in page-set=even mode.
This was the attempt to fix two issues at once:

* [Print 1-page documents in even mode][1]
* Treat non-duplex even reverse printing as second step of manual duplex

Unfortunately due to inverted logic this didn't fix any issues
and introduced new one, outlined above.

This code fixes printing 1-page documents in even mode, and prints
exactly what the user requested in even mode for larger documents,
without inserting extra blank pages.

[cups-filters issue #541][3]

[1]: https://bugs.launchpad.net/ubuntu/+source/cups-filters/+bug/1340435
[2]: OpenPrinting/cups-filters@686a28d
[3]: OpenPrinting/cups-filters#541
@ValdikSS
Copy link

ValdikSS commented Jan 3, 2025

Here's my attempt to fix this issue, and the issue with printing single page document in even mode.
This would not insert extra blank page for the manual duplex, the user need to remove the latest page for second step for odd-paged document themself.

If anyone has ideas on how to distinguish between manual duplex vs just printing even pages in reverse, feel free to contribute. Maybe check whether the printer supports duplex, and assume that everything even-printed in reverse is manual duplex?

@olivluca
Copy link
Author

olivluca commented Jan 3, 2025

This would not insert extra blank page for the manual duplex, the user need to remove the latest page for second step for odd-paged document themself.

I don't understand this sentence: I don't need to do anything for odd-paged documents (and neither for even-paged documents with my workaround mentioned in the original issue), I just have to wait for the odd pages to be printed then feed back the printed stack as is to print the even pages.

@ValdikSS
Copy link

ValdikSS commented Jan 3, 2025

@olivluca

  1. Open 5-page document
  2. Print only odd pages on the printer. You'll get pages 1-3-5.
  3. Remove page 5 list and put pages 1-3 to the printer
  4. Print even pages in reverse. You'll get lists with pages (3)-4, (1)-2. And (5).

If you would not remove the list with page 5, the page 4 would be printed on list 5, page 2 on list 3. You'll end with lists 1-nothing, 2-3, 4-5, and not 1-2, 3-4, 5-nothing.
If you staple the printout without page 5 removed in step 3, you'll have a blank page after page 1.

@ValdikSS
Copy link

ValdikSS commented Jan 3, 2025

"Automated" manual printing, which the fix from 2014 tried to implement, is to insert extra first blank page when printing even pages in reverse. In this case you don't need to remove page 5 list, it would be just "skipped", as in printed in white. The printer would "remove" it for you.

The drawback of such function is that if you're just want to print your 5-page document in even mode in reverse (not manual duplex, just regular print with such unusual settings), you'll have extra blank first page.

@olivluca
Copy link
Author

olivluca commented Jan 3, 2025

If you staple the printout without page 5 removed in step 3, you'll have a blank page after page 1.

you're right, I wonder why I never noticed that.

@olivluca
Copy link
Author

olivluca commented Jan 3, 2025

"Automated" manual printing, which the fix from 2014 tried to implement, is to insert extra first blank page when printing even pages in reverse. In this case you don't need to remove page 5 list, it would be just "skipped", as in printed in white. The printer would "remove" it for you.

Well, I'm confused: in my notes I have that lp does the right thing if the document has an odd number of pages (I guess because at the time it added the extra blank page) and I applied my workaround if the document has an even number of pages (since the extra blank page would mess up the result). Maybe something changed in the meantime? (though I don't see anything in the changelog.Debian of the cups-filters package - edit: pdftopdf is in the cups-filters-core-drivers but it has the same changelog).

@tillkamppeter
Copy link
Member

For cups-filters 2.x fixed in libcupsfilters commit OpenPrinting/libcupsfilters@0d98684e62

tillkamppeter added a commit that referenced this issue Jan 4, 2025
Fixes #541

The page-set option with choicers "even" and "odd" is designed for
doing manual duplex, by printing the odd pages first, turning the
printed pages over and put them back into the input tray and then
print the even pages.

If the total number of pages to be printed is odd, an empty page needs
to be added to the end of the set of even pages to make the total
number of pages even, to have a front and back for each sheet and so
the correct pairs of pages are on each sheet and always all sheets are
taken from the input tray to the output tray.

This did not work correctly for 2 reasons:

- The skipping of pages for the page-set and for the page-ranges
  options were done in the same step, the page ranges must be done
  first and from the resulting pages the even or odd pages need to get
  skipped.

- To determine whether the total amount of pages to be printed is odd,
  only the actually printed pages, with the even or odd pages already
  skipped, ar counted, not the pages which would be printed if
  page-set is not used. This means especially that a 6-page document
  would have 3 even pages, so in the end 3 pages are counted and so an
  extra blank page is added (which is wrong as the document has 6
  pages which is even). A 5-page document has 2 even pages, so an even
  number of pages gets counted and so no blank page gets added.

Now we apply page-ranges and each page which gets printed according to
that we count with the outputno variable. Then we skip the pages with
even or odd outputno depending of the page-set option. In the end,
output no is the number of all pages to be printed and so we know that
if it is odd and we print the even pages, we need to add a blank page.

Backport of OpenPrinting/libcupsfilters@0d98684e62
@tillkamppeter
Copy link
Member

For cups-filters 1.x fixed in cups-filters (1.x branch) commit 3534e01

@ValdikSS
Copy link

ValdikSS commented Jan 4, 2025

@tillkamppeter

The page-set option with choicers "even" and "odd" is designed for doing manual duplex

Is it really? I just checked on Windows, it prints exactly what it say it does: only odd or only even pages, no extra blanks.

With your fix, the option doesn't do what it say. I'm not saying it's not useful, it's just confusing. The options are not named "manual duplex step 1/2", and with this change is limited to odd → put paper again → even+reverse, while you can also do duplex with even+reverse → put paper again → odd, which would result in incorrect printout.

The ticket title is lp -o page-set=even prints an extra blank page, and it still does.

@ValdikSS
Copy link

ValdikSS commented Jan 4, 2025

@tillkamppeter, your fix breaks even-duplex=yes case (hardware duplex).

Previously 5-paged document with page-set=even sides=two-sided-long-edge even-duplex=yes printed page 2 and page 4, and now it prints page 2, page 4, blank page.

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

4 participants