为什么 pagedown::chrome_print() 将纯色 html 元素转换为渐变?

Why is pagedown::chrome_print() converting a solid color html element to a gradient?

我正在使用 datadrivencv R 包生成简历。在 html 中呈现默认简历工作正常,但是当我使用提供的代码(见下文)打印为 pdf 时,边栏从纯色变为渐变色。如果您将 dd_cv.css 文件中的 --sidebar-background-color: 调整为更暗的颜色,例如 --sidebar-background-color: #727273;,这将更容易看到。有什么办法可以避免这种情况吗?

datadrivencv::use_datadriven_cv(
  full_name = "Nick Strayer",
  data_location = "https://docs.google.com/spreadsheets/d/14MQICF2F8-vf8CKPF1m4lyGKO6_thG-4aSwat1e2TWc",
  pdf_location = "https://github.com/nstrayer/cv/raw/master/strayer_cv.pdf",
  html_location = "nickstrayer.me/cv/",
  source_location = "https://github.com/nstrayer/cv"
)
datadrivencv::use_csv_data_storage()

要渲染简历,您必须进入 cv.rmd 文件并在第 25 行将 data_location 更改为 data_location = data/。那么运行

# This script builds both the HTML and PDF versions of your CV

# If you wanted to speed up rendering for googlesheets driven CVs you could use
# this script to cache a version of the CV_Printer class with data already
# loaded and load the cached version in the .Rmd instead of re-fetching it twice
# for the HTML and PDF rendering. This exercise is left to the reader.

# Knit the HTML version
rmarkdown::render("cv.rmd",
                  params = list(pdf_mode = FALSE),
                  output_file = "cv.html")

# Knit the PDF version to temporary html location
tmp_html_cv_loc <- fs::file_temp(ext = ".html")
rmarkdown::render("cv.rmd",
                  params = list(pdf_mode = TRUE),
                  output_file = tmp_html_cv_loc)

# Convert to PDF using Pagedown
pagedown::chrome_print(input = tmp_html_cv_loc,
                       output = "cv.pdf")

Html 截图:

PDF 截图:

我只能在 github 文档预览中重现该问题:https://github.com/OnkarRuikar/catblock/blob/master/test/cv.pdf


但是如果我在 google docs cv 等其他查看器中打开相同的 pdf,它可以正常显示。让我知道您使用的是哪个 PDF 查看器来渲染渐变?

要修复此问题,请遵循 dd_cv.css 中的 CSS 规则:

@page {
    background: 0% 0% / 100% 0.1% linear-gradient(to left, var(--sidebar-background-color) var(--sidebar-background-width), white var(--sidebar-background-width));
}

这是固定的 PDF https://github.com/OnkarRuikar/catblock/blob/master/test/cv_fixed.pdf

您会注意到语言技能栏仍在显示渐变。为此,您需要编辑 cv_printing_functions.R 文件并使用类似的渐变语法修改函数 print_skill_bars。或者在 cv.rmd 文件中为方法调用 CV %>% print_skill_bars(...)

提供您自己的 glue_templet 参数

我在以下软件包版本上创建了 pdf:

# run following commands to get versions of installed packages required by the `datadrivencv`

 pkg = tibble::tibble(
   Package = names(installed.packages()[,3]),
   Version = unname(installed.packages()[,3])
 )
 dplyr::filter(pkg, Package %in% c("dplyr", "tidyr", "glue", "readr", "googlesheets4", "lubridate", " purrr", "stringr", "magrittr", "pagedown", "fs", "icon", "whisker", "knitr", "rmarkdown" ,"testthat"))

Following are the versions installed on my machine at the moment:
# A tibble: 15 x 2
   Package       Version
   <chr>         <chr>  
 1 dplyr         1.0.7  
 2 fs            1.5.0  
 3 glue          1.4.2  
 4 googlesheets4 1.0.0  
 5 icon          0.1.0  
 6 knitr         1.36   
 7 lubridate     1.8.0  
 8 magrittr      2.0.1  
 9 pagedown      0.15   
10 readr         2.1.0  
11 rmarkdown     2.11   
12 stringr       1.4.0  
13 testthat      3.1.0  
14 tidyr         1.1.4  
15 whisker       0.4