davidgohel / officer

:cop: officer: office documents from R
https://ardata-fr.github.io/officeverse/
Other
601 stars 107 forks source link

body_replace_img_at_bkm combined with external_img places image with wrong size #198

Closed LukasK13 closed 5 years ago

LukasK13 commented 5 years ago

Hi davidgohel,

First of all, your package is absolutely amazing and really helpful. Thanks for your work!

However, it seems like the function body_replace_img_at_bkm() in combination with external_img pastes images not with the given width and height into a Word-document. To be more precise, I get the correct sizing, when I divide the target size in inches by 72 and use this value for width and height. The bug can be reproduced with any simple document. I'm not sure, if there's a way for to provide the Word-document and the used image for you. Please let me know. Anyway, the code I used for this purpose was:

library(officer)

document = read_docx("Test.docx")
body_replace_img_at_bkm(document, "MyBookmark", external_img("Image.jpg", width = 6, height = 4))
print(document, target = "Result.docx")

The word document only contained the bookmark MyBookmark.

This code did the trick for me (notice the introduced factor):

library(officer)

factor = 1/72
document = read_docx("Test.docx")
body_replace_img_at_bkm(document, "MyBookmark", external_img("Image.jpg", width = 6*factor, height = 4*factor))
print(document, target = "Result.docx")

Of course,I used the newest version of your package and all the other packages are also up to date. I hope, you can reproduce the bug with the given information. If not, don't hesitate to ask for more information.

sessionInfo() gave me the following output:

R version 3.5.2 (2018-12-20)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /usr/lib64/R/lib/libRblas.so

locale:
 [1] LC_CTYPE=C                 LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] fullcalendar_0.0.0.9000 future_1.12.0           promises_1.0.1          ldapr_0.1.0             openssl_1.2.2           rintrojs_0.2.1          officer_0.3.3          
 [8] xml2_1.2.0              gitlabr_1.1.6           magrittr_1.5            SummeRnote_1.0          yaml_2.2.0              jsonlite_1.6            data.table_1.12.0      
[15] RMySQL_0.10.17          DBI_1.0.0               colourpicker_1.0        lubridate_1.7.4         RColorBrewer_1.1-2      dtplyr_0.0.3            dbplyr_1.3.0           
[22] dplyr_0.8.0.1           plotly_4.8.0            ggplot2_3.1.0           bcrypt_1.1              DT_2.0.0                SweetAleRt_1.0          shinyBS_0.61           
[29] shinyWidgets_0.4.8      shinyjs_1.0             shinydashboard_0.7.1    shiny_1.2.0            

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.1        tidyr_0.8.3       arpr_0.1.1        listenv_0.7.0     assertthat_0.2.0  digest_0.6.18     V8_2.1            mime_0.6          R6_2.4.0         
[10] plyr_1.8.4        httr_1.4.0        pillar_1.3.1      rlang_0.3.1       curl_3.3          lazyeval_0.2.2    uuid_0.1-2        rstudioapi_0.10   miniUI_0.1.1.1   
[19] stringr_1.4.0     htmlwidgets_1.3   munsell_0.5.0     compiler_3.5.2    httpuv_1.5.0      pkgconfig_2.0.2   askpass_1.1       base64enc_0.1-3   globals_0.12.4   
[28] htmltools_0.3.6   tidyselect_0.2.5  tibble_2.1.1      codetools_0.2-16  viridisLite_0.3.0 crayon_1.3.4      withr_2.1.2       later_0.8.0       grid_3.5.2       
[37] xtable_1.8-3      gtable_0.2.0      scales_1.0.0      zip_2.0.1         stringi_1.4.3     tools_3.5.2       glue_1.3.1        purrr_0.3.2       crosstalk_1.0.0  
[46] colorspace_1.4-1
davidgohel commented 5 years ago

It should be solved now - thanks to PR #199

github-actions[bot] commented 2 years ago

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue and link to this old issue if necessary.