gpt4 book ai didi

r - 使用 pdftools 包和 png 包将 pdf 转换为 png 图像给出不完整的 png

转载 作者:行者123 更新时间:2023-12-04 13:46:38 27 4
gpt4 key购买 nike

我有这个带点的荷兰 pdf 图像:

pdf image of the netherlands with dots

当我尝试将此 pdf 转换为 png 图像时,使用 pdftoolspng像这样:

library(png)
library(pdftools)
bitmap <- pdf_render_page("netherlands.pdf", page = 1, dpi = 300)
png::writePNG(bitmap, "netherlands.png"))

结果是这样的:

png image of the netherlands without dots

没有 pdf 版本中显示的点的图像。

我怎么解决这个问题?

这是我的 session 信息:
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows Server 2008 R2 x64 (build 7601) Service Pack 1

locale:
[1] LC_COLLATE=Dutch_Netherlands.1252 LC_CTYPE=Dutch_Netherlands.1252 LC_MONETARY=Dutch_Netherlands.1252
[4] LC_NUMERIC=C LC_TIME=Dutch_Netherlands.1252

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

other attached packages:
[1] png_0.1-7 pdftools_1.4 psych_1.6.9 psy_1.1 maptools_0.8-41
[6] rgeos_0.3-21 rgdal_1.2-5 sp_1.2-4 tagcloud_0.6 Rcpp_0.12.12
[11] wordcloud_2.5 directlabels_2015.12.16 extrafont_0.17 haven_1.0.0 tm_0.6-2
[16] NLP_0.1-9 qdap_2.2.5 RColorBrewer_1.1-2 qdapTools_1.3.1 qdapRegex_0.6.0
[21] qdapDictionaries_1.0.6 tidyr_0.6.1 dplyr_0.5.0 readxl_1.0.0 reshape2_1.4.2
[26] Hmisc_4.0-2 Formula_1.2-1 survival_2.40-1 lattice_0.20-34 knitr_1.15.1
[31] ggthemes_3.4.0 ggplot2_2.2.1 rmarkdown_1.4

loaded via a namespace (and not attached):
[1] splines_3.3.2 gender_0.5.1 gtools_3.5.0 assertthat_0.1 latticeExtra_0.6-28 xlsxjars_0.6.1
[7] cellranger_1.1.0 yaml_2.1.14 slam_0.1-40 Rttf2pt1_1.3.4 backports_1.0.4 quadprog_1.5-5
[13] extrafontdb_1.0 chron_2.3-48 digest_0.6.12 colorspace_1.3-2 htmltools_0.3.5 Matrix_1.2-7.1
[19] plyr_1.8.4 XML_3.98-1.5 scales_0.4.1 gdata_2.17.0 htmlTable_1.7 tibble_1.2
[25] openNLP_0.2-6 reports_0.1.4 nnet_7.3-12 lazyeval_0.2.0 mnormt_1.5-5 magrittr_1.5
[31] evaluate_0.10 foreign_0.8-67 tools_3.3.2 data.table_1.10.0 stringr_1.1.0 xlsx_0.5.7
[37] munsell_0.4.3 cluster_2.0.5 plotrix_3.6-4 RCurl_1.95-4.8 igraph_1.0.1 labeling_0.3
[43] bitops_1.0-6 base64enc_0.1-3 venneuler_1.1-0 gtable_0.2.0 DBI_0.5-1 R6_2.2.0
[49] gridExtra_2.2.1 openNLPdata_1.5.3-2 rprojroot_1.1 rJava_0.9-8 stringi_1.1.2 parallel_3.3.2
[55] rpart_4.1-10 acepack_1.4.1

最佳答案

更新: pdf 在 MacOS 上呈现良好(见下文)。我认为问题在于 pdf 文件使用了 Windows 上不可用的字体。在 Windows 上,我看到:

> pdf_fonts("~/../Downloads/netherlands_pdf.pdf")
Warning: error: Couldn't find a font for 'ZapfDingbats', subst is 'Helvetica'
name type embedded file
1 ZapfDingbats type1 FALSE C:\\Windows\\Fonts\\arial.ttf

渲染PDF时,我看到:
> bitmap <- pdf_render_page("~/../Downloads/netherlands_pdf.pdf")
Warning: error: No display font for 'ArialNarrow'
Warning: error: No display font for 'ArialNarrow,Bold'
Warning: error: No display font for 'ArialNarrow,Italic'
Warning: error: No display font for 'ArialNarrow,BoldItalic'
Warning: error: No display font for 'ArialNarrow-Bold'
Warning: error: No display font for 'ArialNarrow-Italic'
Warning: error: No display font for 'ArialNarrow-BoldItalic'
Warning: error: No display font for 'HelveticaNarrow'
Warning: error: No display font for 'HelveticaNarrow,Bold'
Warning: error: No display font for 'HelveticaNarrow,Italic'
Warning: error: No display font for 'HelveticaNarrow,BoldItalic'
Warning: error: No display font for 'HelveticaNarrow-Bold'
Warning: error: No display font for 'HelveticaNarrow-Italic'
Warning: error: No display font for 'HelveticaNarrow-BoldItalic'
Warning: error: No display font for 'BookAntiqua'
Warning: error: No display font for 'BookAntiqua,Bold'
Warning: error: No display font for 'BookAntiqua,Italic'
Warning: error: No display font for 'BookAntiqua,BoldItalic'
Warning: error: No display font for 'BookAntiqua-Bold'
Warning: error: No display font for 'BookAntiqua-Italic'
Warning: error: No display font for 'BookAntiqua-BoldItalic'
Warning: error: No display font for 'ArialUnicode'

因此,我怀疑这些点实际上是使用字体(可能是 dingbat)打印的,但如果此字体不可用,则无法呈现它们。

在 OSX 上没有这样的警告,输出似乎是正确的:

enter image description here

但是我不确定为什么 pdf 在 Windows 上的 Chrome 中正确显示。也许 Chrome 包括额外的字体?

关于r - 使用 pdftools 包和 png 包将 pdf 转换为 png 图像给出不完整的 png,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46057474/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com