ardata-fr / doconv

Other
13 stars 1 forks source link

The number of pages updates incorrectly #4

Closed OliBravo closed 1 year ago

OliBravo commented 1 year ago

Hi, I use doconv for updating the table of contents as well as lists of tables and figures. I noticed that the number of pages updates incorrectly. To instert the number of pages I use officer::run_word_field function in my Rmd script. Here's a minimal reproducible example:

1) rmarkdown (save it as 'index.Rmd')

    ---
    output: officedown::rdocx_document
    ---

    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
## Number of pages

Pages in the document: `r officer::run_word_field("NumPages  \\* MERGEFORMAT")`

\newpage

## Page 1

\newpage

## Page 2

\newpage

## Page 3

\newpage

## Page 4

2) Testing code

library(rmarkdown) library(doconv)

render( input = "index.Rmd" )

docx_update("index.docx")



When I open the updated Word document I see the field with the number of pages shows 2, but there are 5 pages actually in the document. Is it a bug or am I doing something wrong?
davidgohel commented 1 year ago

Hello

The script that update the page number is there: https://github.com/ardata-fr/doconv/blob/main/inst/scripts/powershell/docxupdate.ps1

Maybe you will find an issue related to your case.

On my machine, it works as expected, TBH I already had this issue many times. This is Word that has sometimes a problem... Often, refreshing again fixes the issue

Capture d’écran 2023-02-15 à 14 45 45