Bug 125682 - Wrong calculation number of pages(field NUMPAGES) if page numbering(field PAGE) starts from EVEN number
Summary: Wrong calculation number of pages(field NUMPAGES) if page numbering(field PAG...
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
6.0 all versions
Hardware: All All
: medium normal
Assignee: Michael Stahl (CIB)
URL:
Whiteboard: target:7.0.0 target:6.4.2 target:6.3.6
Keywords: bibisected, bisected, filter:docx, regression
Depends on:
Blocks:
 
Reported: 2019-06-04 13:38 UTC by Alexey
Modified: 2020-05-27 15:20 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Example of WRONG page counting, when page numbering starts from EVEN number (5.53 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2019-06-04 13:42 UTC, Alexey
Details
Example of PDF document with WRONG page counting, when page numbering starts from EVEN number (8.07 KB, application/pdf)
2019-06-04 13:44 UTC, Alexey
Details
Example of CORRECT page counting in docx document, if page numbering starts from ODD number (5.53 KB, application/vnd.openxmlformats-officedocument.wordprocessingml.document)
2019-06-04 13:46 UTC, Alexey
Details
comparison MSO 2010 and LibreOffice 6.5 Master (163.23 KB, image/png)
2019-12-11 13:41 UTC, Xisco Faulí
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexey 2019-06-04 13:38:36 UTC
Description:
We are developing web editor of docx documents. And to convert html code generated by user to docx/pdf document we use CLI of libreoffice. 
We have noticed a strange behavior in how libbreoffice counts number of pages in the document. If numeration of pages starts from EVEN number - then it wrong calculates count of pages, adding extra 1. For example if document consists of 2 real pages, and starting page number is 2 - page counter(field NUMPAGES) shows '3'; Starting of numeration was set but manually changing attribute 'w:start' of tag <w:pgNumType> '<w:pgNumType w:fmt="decimal" w:start="2"/>' for page section. We use only one section for entire document.
Same issue happens when we are trying to convert docx document to pdf document using console libreoffice. Resulted pdf document also shows wrong count of pages - same as it was in source docx-document.

So issue happened only when we set start of page numbering from EVEN page number, for odd page number everything is going well.

GUI mode of libbreoffice also shows wrong number of pages in the document. MS Word displays it correctly.

So my question is if there is some approach to fix this behavior by amending internal xml code. Thanks in advance. Attaching examples of docx documents with ODD and EVEN starting page number. 

Steps to Reproduce:
1. Create new docx document in libreoffice of 2 pages.
2. Insert field 'Page Number'.
3. Insert filed 'Page Count'.
4. Unzip created docx file.
5. Within the  file 'word/document.xml' add attribute 'w:start' to tag '<w:pgNumType>' with any EVEN value: 2,4,6 etc. Resulted tag should be <w:pgNumType w:fmt="decimal" w:start="2"/>.
6. Zip all files again to docx file.
7. Open resulted file from step 6 in LibreOffice.
8. Export resulted file as PDF document.

Actual Results:
Page count field displays figure '3' in both docx and pdf files.

Expected Results:
Page count field displays figure '2' in both docx and pdf files, since it's real number of pages in documents.


Reproducible: Always


User Profile Reset: No



Additional Info:


Version: 6.0.6.2
Build ID: 0c292870b25a325b5ed35f6b45599d2ea4458e77
CPU threads: 4; OS: Mac OS X 10.14.5; UI render: default; 
Locale: ru-RU (ru_RU.UTF-8); Calc: group
Comment 1 Alexey 2019-06-04 13:42:16 UTC
Created attachment 151904 [details]
Example of WRONG page counting, when page numbering starts from EVEN number
Comment 2 Alexey 2019-06-04 13:44:36 UTC
Created attachment 151905 [details]
Example of PDF document with WRONG page counting, when page numbering starts from EVEN number
Comment 3 Alexey 2019-06-04 13:46:07 UTC
Created attachment 151906 [details]
Example of CORRECT page counting in docx document, if page numbering starts from ODD number
Comment 4 Xisco Faulí 2019-12-11 13:41:26 UTC
Created attachment 156492 [details]
comparison MSO 2010 and LibreOffice 6.5 Master
Comment 5 Xisco Faulí 2019-12-11 13:41:36 UTC
Reproduced in

Version: 6.5.0.0.alpha0+
Build ID: b9d6ea1dd7541c4bd866571f9e3f0aa894687c07
CPU threads: 4; OS: Linux 4.15; UI render: default; VCL: gtk3; 
Locale: ca-ES (ca_ES.UTF-8); UI-Language: en-US
Calc: threaded
Comment 6 Xisco Faulí 2019-12-11 13:53:06 UTC
Regression introduced by:

https://cgit.freedesktop.org/libreoffice/core/commit/?id=14bb680949b47332d2921cc68f75340b31ad5c32

author	Luke Deller <luke@deller.id.au>	2017-07-12 20:39:50 +1000
committer	Miklos Vajna <vmiklos@collabora.co.uk>	2017-09-01 10:45:43 +0200
commit	14bb680949b47332d2921cc68f75340b31ad5c32 (patch)
tree	66fe5b9a055956a2affe8b2a12561fcf7fbc00ab
parent	feb463e93f8c7beb0f6abb52812ac05c4f7724c2 (diff)
Insert blank page when first page number is even

Bisected with: bibisect-linux64-6.0

Adding Cc: to Luke Deller
Comment 7 Commit Notification 2020-02-19 15:50:03 UTC
Michael Stahl committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/509a02aa96f6d7620cb0bf06c20b3bfa0641be92

tdf#125682 sw: don't insert empty page before first page with even number

It will be available in 7.0.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 8 Michael Stahl (CIB) 2020-02-19 15:58:29 UTC
should be fixed on master
Comment 9 Xisco Faulí 2020-02-24 11:26:17 UTC
Verified in

Version: 7.0.0.0.alpha0+
Build ID: f32a59a52e3ee2a0a8df9bb76bc1ff0ada7c7f1d
CPU threads: 4; OS: Linux 4.19; UI render: default; VCL: gtk3; 
Locale: en-US (en_US.UTF-8); UI-Language: en-US
Calc: threaded

@Michael, thanks for fixing this issue!
Comment 10 Commit Notification 2020-02-24 14:50:59 UTC
Michael Stahl committed a patch related to this issue.
It has been pushed to "libreoffice-6-4":

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

tdf#125682 sw: don't insert empty page before first page with even number

It will be available in 6.4.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 11 Commit Notification 2020-02-26 09:11:32 UTC
Michael Stahl committed a patch related to this issue.
It has been pushed to "libreoffice-6-3":

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

tdf#125682 sw: don't insert empty page before first page with even number

It will be available in 6.3.6.

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.