Bug 163126 - Brochure printing A5 pages to A4 paper doesn't scale correctly
Summary: Brochure printing A5 pages to A4 paper doesn't scale correctly
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
24.2.5.2 release
Hardware: x86-64 (AMD64) macOS (All)
: medium normal
Assignee: Patrick (volunteer)
URL:
Whiteboard: target:25.8.0 target:25.2.0.2 target:...
Keywords:
Depends on:
Blocks: Print
  Show dependency treegraph
 
Reported: 2024-09-24 11:46 UTC by James R
Modified: 2025-01-12 23:35 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
The document I have been printing (86.82 KB, application/vnd.oasis.opendocument.text)
2024-09-24 11:47 UTC, James R
Details
Printed output from RWTS "print to PDF" printer (2.62 MB, application/pdf)
2024-09-24 20:46 UTC, Patrick (volunteer)
Details
Print dialog screenshot (466.10 KB, image/png)
2024-12-17 11:29 UTC, James R
Details
Snapshot with "Brochure" checkbox checked and default macOS "post processing" settings (1016.35 KB, image/png)
2024-12-19 19:52 UTC, Patrick (volunteer)
Details
macOS print dialog with test file after fix (1015.85 KB, image/png)
2024-12-27 23:08 UTC, Patrick (volunteer)
Details

Note You need to log in before you can comment on or make changes to this bug.
Description James R 2024-09-24 11:46:40 UTC
Description:
MacBook Pro (2020) running OS Sonoma 14.6.1
Epson XP-960 printer
LibreOffice 24.2.5.2

I have a Writer document consisting of four A5 portrait pages, and I wish to print it out as a brochure on two sides of an A4 sheet.
The printer is loaded with A4 paper
In the print dialog I selected double sided "On (Short Edge)
Under the LibreOffice heading I selected “Brochure”
Under the Paper Handling heading I toggled “Scale to Fit to Paper Size” to ‘On’, selected the “Destination Paper Size” to be “A4 Borderless”, and made sure that “Scale Down Only” was not selected.

However, when I print the document it comes out as an A5 size printout in the middle of an A4 sheet.

Steps to Reproduce:
1.Create A5 document of 4 or more pages
2.Select 'Print'
3.In the 'LibreOffice' pane select brochure
4.Under 'Double-sided' select 'On (Short Edge)'
5.Under 'Paper Handling' select 'Scale to Fit Paper Size' and under 'Destination Paper Size' choose 'A4' or 'A4 Borderless'
6. Click 'Print' 

Actual Results:
The printer prints a double sided brochure with the print occupying A5 size space centred on the A4 paper.

Expected Results:
The printer should prints a double sided brochure with the print occupying the whole of the A4 paper.


Reproducible: Always


User Profile Reset: Yes

Additional Info:
Version:  24.2.5.2 (X86_64) / LibreOffice Community
Build: bffef4ea93e59bebbeaf7f431bb02b1a39ee8a59
Environment:  CPU threads: 8; OS: macOS 14.6.1
User Interface:  UI render: Skia/Raster; VCL: osx
Locale:  en-GB (en_GB.UTF-8); UI: en-US
Misc:  Calc: threaded

If instead of printing the document straight from the print dialog I choose “Open in Preview” from the PDF dropdown menu at the bottom of the Print dialog, the document opens in its brochure layout correctly in Preview, and can be printed from there by choosing a scale factor of 141% and then selecting 'Print'

I am also finding that when I have printed using steps 1 to 6 above when I return to LibreOffice it has frozen and I have to Force Quit and relaunch
Comment 1 James R 2024-09-24 11:47:55 UTC
Created attachment 196646 [details]
The document I have been printing
Comment 2 Alex Thurgood 2024-09-24 15:42:54 UTC
Thanks @James

Unfortunately, I'm away from my office at the moment, so can't test, but will do so when I get back.
Comment 3 Patrick (volunteer) 2024-09-24 20:46:55 UTC
Created attachment 196662 [details]
Printed output from RWTS "print to PDF" printer

I cannot reproduce this bug. I followed the same steps except for one thing: I don't have any double-sided options for my printer in the native print dialog but that is probably due to the fact that I am using the following "print to PDF" printer:

https://github.com/rodyager/RWTS-PDFwriter/releases
Comment 4 James R 2024-12-17 11:20:16 UTC
Like Patrick, if I don't print from within LibreOffice, I seem to be able to avoid the problem. It often/ usually seems to work for me if I select 'Open in Preview' from the 'PDF' dropdown in the print dialog, and then print from within Preview. It seems to me that LibreOffice is not responding to the 'Scale to Fit Paper Size' option in the Print Dialog (ringed in the attached screenshot), Whatever the problem is, it seems to have been resolved by the developer(s) of the final version of NeoOffice (https://github.com/neooffice/NeoOffice)
Comment 5 James R 2024-12-17 11:29:53 UTC
Created attachment 198155 [details]
Print dialog screenshot
Comment 6 Patrick (volunteer) 2024-12-19 19:50:25 UTC
(In reply to James R from comment #5)
> Created attachment 198155 [details]
> Print dialog screenshot

So I see you are using the macOS "post processing" features to layout two pages on each A5 page. The problem with changing anything other than the "LibreOffice" section of the print dialog is that they are applied by macOS (using whatever algorithms macOS has implemented) after LibreOffice has drawn its content.

One thing I noticed is that with my fix for tdf#161623, if I immediately check the "Brochure" checkbox in the "LibreOffice" section, the preview pane rerenders all of the pages to be 2 pages for A5 sheet. The PDF is similar to your snapshot but I notice that with the "Brochure", the margins are narrower and content expands to fill that extra space.

I think something is wrong with the "Brochure" checkbox as I have found that if it is checked when the print dialog is first displayed, the setting is ignored and the paper is not rotated. But toggling that checkbox off and back on seems to force the margins to be the same as in NeoOffice.

Is it possible that part of the cause of this bug is the flaky "Brochure" checkbox?
Comment 7 Patrick (volunteer) 2024-12-19 19:52:32 UTC
Created attachment 198183 [details]
Snapshot with "Brochure" checkbox checked and default macOS "post processing" settings
Comment 8 James R 2024-12-19 23:50:13 UTC
(In reply to Patrick (volunteer) from comment #6)
> (In reply to James R from comment #5)
> > Created attachment 198155 [details]
> > Print dialog screenshot
Your understanding of what I’m doing is mostly correct. The document is set up in A5 pages which I then want to print on A4 paper to make a brochure. The problem I am experiencing is that it prints them out on A4 paper, but with the two A5 pages reduced to a print which is a single A5 in size - i.e. reduced by about 70%. This happens even when I select the ‘scale to fit paper size’ option for A4 paper. The preview in the dialog gives no indication that it is going to print a smasllnimage on a large sheet.

I am away from my laptop at the moment, and can’t remember whether the same issue occurs if i select to print two pages side by side.

I too have encountered the need to toggle brochure off and on again to get the correct preview.
Comment 9 Patrick (volunteer) 2024-12-20 15:52:42 UTC
(In reply to James R from comment #8)
> Your understanding of what I’m doing is mostly correct. The document is set
> up in A5 pages which I then want to print on A4 paper to make a brochure.
> The problem I am experiencing is that it prints them out on A4 paper, but
> with the two A5 pages reduced to a print which is a single A5 in size - i.e.
> reduced by about 70%. This happens even when I select the ‘scale to fit
> paper size’ option for A4 paper. The preview in the dialog gives no
> indication that it is going to print a smasllnimage on a large sheet.

That's pretty strange. I did 2 different runs and printed to my "print to PDF file" RWTS printer and that "printer" generates landscape A4 pages with two A5 pages per A4 page.

- My first run:
  - Check "Brochure" checkbox
  - Leave Layout > Pages per Sheet at "1"
  - Enable "Paper Handling > Scale to Fit Paper Size"
  - Set "Paper Handling > Destination Paper Size" to "A4"
  - Press "Print" button

- My second run:
  - Leave "Brochure" checkbox unchecked
  - Leave Layout > Pages per Sheet at "2"
  - Enable "Paper Handling > Scale to Fit Paper Size"
  - Set "Paper Handling > Destination Paper Size" to "A4"
  - Press "Print" button

My first guess is that the Paper Handling is done is a macOS or print driver post processing step. But do you get A4 paper output with NeoOffice with the above step? If so, maybe LibreOffice is doing something not obvious that is messing up the print job?
Comment 10 Alex Thurgood 2024-12-20 17:45:14 UTC
I can reproduce this with the test file from bug 164354 and

Version: 25.8.0.0.alpha0+ (AARCH64) / LibreOffice Community
Build ID: 2f5e75ed134cfd0224e03411ca9d7d81f319c91b
CPU threads: 8; OS: macOS 15.1.1; UI render: Skia/Raster; VCL: osx
Locale: fr-FR (fr_FR.UTF-8); UI: en-US
Calc: threaded

Printer at home is a HP Pagewide Pro 477dw MFP

The printed output appears cut off across the A4 page, even if I choose the short edge double sided option, Brochure option ticked.

The print preview in the macOS print dialog shows the correct representation, and if I save to PDF from this dialog, I get the intended brochure layout. It seems that LO manages to somehow mess up the instructions sent to the printer subsystem.
Comment 11 Patrick (volunteer) 2024-12-21 15:00:42 UTC
(In reply to Alex Thurgood from comment #10)
> The printed output appears cut off across the A4 page, even if I choose the
> short edge double sided option, Brochure option ticked.
> 
> The print preview in the macOS print dialog shows the correct
> representation, and if I save to PDF from this dialog, I get the intended
> brochure layout. It seems that LO manages to somehow mess up the
> instructions sent to the printer subsystem.

OK. I just open the print dialog with the document in tdf#164354 (which has the "Brochure" checkbox already bchecked by default) and I apply none of the post processing settings in comment #9, print to Preview appears to layout the pages correctly, but the Preview application's Inspector dialog shows a huge paper size (215.9 cm x 279.4 cm).

Then, if I repeat the above step but this time I toggle the "Brochure" checkbox off and then back on, print to Preview also appears to layout the pages correctly, but this time the Preview application's Inspector shows the paper size to be A5 instead A4. So I think I am now able to reproduce what @James R described in comment #8.

I think I will need to read through LibreOffice's printing code and compare it to NeoOffice code. In the first case above, print to Preview in NeoOffice produces A4 pages with the correct layout.

But in the second case, NeoOffice produces the same A5 pages just like LibreOffice so I will focus on the first case as the second case appears to be a LibreOffice bug that is triggered by toggling of the "Brochure" checkbox.
Comment 12 Commit Notification 2024-12-27 17:04:39 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/5bd6ef607d68d371b93ad438fb24e2d8fc352b10

tdf#163126 Fix incorrect paper size and rotation when printing a brochure

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 13 Patrick (volunteer) 2024-12-27 19:41:19 UTC
I have committed a fix for this bug. The fix will be in tomorrow's (28 December 2024) nightly master builds. With the fix, you should *not* need to use the print dialog's Page Layout or Paper Handling post-processing settings. The fix should properly set the page size to A4 and, if the "Brochure" checkbox is checked, the print dialog should show two A5 pages on each A4 page:

https://dev-builds.libreoffice.org/daily/master/current.html

Note for macOS testers: the nightly master build installer does not overwrite any LibreOffice official versions. Instead, it will be installed as a separate application called "LibreOfficeDev" in the /Applications folder.

Because this is a "test" build, you will need to do the following steps before you launch the LibreOfficeDev application:

1. Go to the Finder and navigate to the /Applications/Utilities folder
2. Launch the "Terminal" application
3. Paste the following command in the Terminal application window and press the Return key to execute the command:

   xattr -d com.apple.quarantine /Applications/LibreOfficeDev.app
Comment 14 Patrick (volunteer) 2024-12-27 23:08:13 UTC
Created attachment 198300 [details]
macOS print dialog with test file after fix

With my, I opened the document in attachment #196646 [details], select the File > Print menu item, and then the only thing I changed in the native print dialog was I checked the "Brochure" checkbox. Then, opening in Preview displayed a PDF set to A4 with two A5 document pages per A4 page.
Comment 15 Commit Notification 2024-12-31 06:01:42 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/fbe75cef326dfe2e97bf0f80e1510f74ed712fa8

tdf#163126 Fix incorrect paper size and rotation when printing a brochure

It will be available in 25.2.0.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 16 Commit Notification 2024-12-31 06:01:45 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/2fa4dd608617348125596a5ea3e9dfb911a828ff

tdf#163126 Fix incorrect paper size and rotation when printing a brochure

It will be available in 24.8.5.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 17 James R 2025-01-09 12:50:12 UTC
I have now tested the latest build (libreoffice-24-8/MacOSX-x86_64@tb92-TDF/2025-01-09_04.27.52/) and brochure printing is now working correctly. Thank you very much. The only oddity is that when the print dialog comes up, if I click the Brochure checkbox to toggle it either off or on, the print dialog simply closes. If i reinvoke the Print command the dialog reappears with the correct new brochure setting which I have just applied.
Comment 18 Patrick (volunteer) 2025-01-09 13:40:29 UTC
I see the same as you: checking or unchecking the Brochure checkbox closes but does not reopen the native print dialog.

I remember that working so I will take a look at my changes and see if I can fix that.
Comment 19 Patrick (volunteer) 2025-01-09 15:22:19 UTC
Looks like my fix for tdf#159995 caused the failure to automatically reopen the print dialog:

commit 09484a1befd41681276cc9909b3228e5bf28a76e
Author: Patrick Luby <guibmacdev@gmail.com>
Date:   Sun Dec 29 11:20:11 2024 -0500

    Related: tdf#159995 fix pages per sheet in the non-native print dialog
Comment 20 Patrick (volunteer) 2025-01-09 22:11:42 UTC
I have uploaded a patch that fixes the failure to reopen the print dialog after changing the "Print selection only" or "Brochure" checkboxes that doesn't break my fix for tdf#159995:

https://gerrit.libreoffice.org/c/core/+/180036

I'll post again when I know when it will be included in the nightly master builds.
Comment 21 Commit Notification 2025-01-10 12:15:24 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/0dfecee85589abfb94d9fa0cc8129c4fdbaf696c

Related: tdf#163126 fix failure to restart print job

It will be available in 25.8.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 22 Patrick (volunteer) 2025-01-10 12:21:51 UTC
I have committed a fix the print dialog reopening failure. The fix should be in tomorrow's (11 January 2025) nightly master builds:

https://dev-builds.libreoffice.org/daily/master/current.html

Note for macOS testers: the nightly master build installer does not overwrite any LibreOffice official versions. Instead, it will be installed as a separate application called "LibreOfficeDev" in the /Applications folder.

Because this is a "test" build, you will need to do the following steps before you launch the LibreOfficeDev application:

1. Go to the Finder and navigate to the /Applications/Utilities folder
2. Launch the "Terminal" application
3. Paste the following command in the Terminal application window and press the Return key to execute the command:

   xattr -d com.apple.quarantine /Applications/LibreOfficeDev.app
Comment 23 Commit Notification 2025-01-12 14:06:32 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/a539acabcf89e7edd1ee7314752ea5c95edbd59d

Related: tdf#163126 fix failure to restart print job

It will be available in 25.2.0.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 24 Commit Notification 2025-01-12 23:35:28 UTC
Patrick Luby committed a patch related to this issue.
It has been pushed to "libreoffice-24-8":

https://git.libreoffice.org/core/commit/1c6414dde0122f2418f7948263ee1813078d40c8

Related: tdf#163126 fix failure to restart print job

It will be available in 24.8.5.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.