Skip to content

Commit

Permalink
Correct skipping even/odd pages for manual duplex
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tillkamppeter committed Jan 3, 2025
1 parent dc02447 commit 0d98684
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
3 changes: 2 additions & 1 deletion cupsfilters/pdftopdf/pdftopdf-processor-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ _cfPDFToPDFProcessingParameters()
int copies_to_be_logged;

// helper functions
bool even_odd_page(int outno) const; // 1 based
bool with_page(int outno) const; // 1 based
bool have_page(int pageno) const; //1 based
bool have_page(int pageno) const; // 1 based
void dump(pdftopdf_doc_t *doc) const;
};

Expand Down
55 changes: 34 additions & 21 deletions cupsfilters/pdftopdf/pdftopdf-processor.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ BookletMode_dump(pdftopdf_booklet_mode_e bkm,
// }}}

bool
_cfPDFToPDFProcessingParameters::with_page(int outno) const // {{{
_cfPDFToPDFProcessingParameters::even_odd_page(int outno) const // {{{
{
if (outno % 2 == 0)
{ // 1-based
Expand All @@ -41,6 +41,13 @@ _cfPDFToPDFProcessingParameters::with_page(int outno) const // {{{
}
else if (!odd_pages)
return (false);
return (true);
}
// }}}

bool
_cfPDFToPDFProcessingParameters::with_page(int outno) const // {{{
{
return (page_ranges.contains(outno));
}
// }}}
Expand Down Expand Up @@ -416,18 +423,21 @@ _cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,
{
if ((curpage) && (param.with_page(outputpage)))
{
curpage->rotate(param.orientation);
if (param.mirror)
curpage->mirror();
// TODO? update rect? --- not needed any more
proc.add_page(curpage, param.reverse); // reverse -> insert at beginning
// Log page in /var/log/cups/page_log
outputno ++;
if (param.page_logging == 1)
if (doc->logfunc) doc->logfunc(doc->logdata,
CF_LOGLEVEL_CONTROL,
"PAGE: %d %d", outputno,
param.copies_to_be_logged);
if (param.even_odd_page(outputno))
{
curpage->rotate(param.orientation);
if (param.mirror)
curpage->mirror();
// TODO? update rect? --- not needed any more
proc.add_page(curpage, param.reverse); // reverse -> insert at beginning
// Log page in /var/log/cups/page_log
if (param.page_logging == 1)
if (doc->logfunc) doc->logfunc(doc->logdata,
CF_LOGLEVEL_CONTROL,
"PAGE: %d %d", outputno,
param.copies_to_be_logged);
}
}
curpage = proc.new_page(param.page.width, param.page.height, doc);
outputpage++;
Expand Down Expand Up @@ -481,16 +491,19 @@ _cfProcessPDFToPDF(_cfPDFToPDFProcessor &proc,
}
if ((curpage) && (param.with_page(outputpage)))
{
curpage->rotate(param.orientation);
if (param.mirror)
curpage->mirror();
proc.add_page(curpage, param.reverse); // reverse -> insert at beginning
// Log page in /var/log/cups/page_log
outputno ++;
if (param.page_logging == 1)
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_CONTROL,
"PAGE: %d %d", outputno,
param.copies_to_be_logged);
if (param.even_odd_page(outputno))
{
curpage->rotate(param.orientation);
if (param.mirror)
curpage->mirror();
proc.add_page(curpage, param.reverse); // reverse -> insert at beginning
// Log page in /var/log/cups/page_log
if (param.page_logging == 1)
if (doc->logfunc) doc->logfunc(doc->logdata, CF_LOGLEVEL_CONTROL,
"PAGE: %d %d", outputno,
param.copies_to_be_logged);
}
}

if ((param.even_duplex || !param.odd_pages) && (outputno & 1))
Expand Down

0 comments on commit 0d98684

Please sign in to comment.