4

I have this pdf image of the Netherlands with dots:

pdf image of the netherlands with dots

When I try to convert this pdf to a png image, using pdftools and png like this:

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

The result is this:

png image of the netherlands without dots

An image without the dots that were shown in the pdf version.

How can I solve this problem?

Here is my sessioninfo:

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
rdatasculptor
  • 7,612
  • 13
  • 54
  • 78

1 Answers1

1

update: The pdf renders fine on MacOS (see below). I think the problem is that the pdf file uses a font which not available on Windows. On Windows I see:

> 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

When rendering the PDF I see:

> 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'

So I suspect that the dots are actually printed using a font (probably a dingbat) but they cannot be rendered if this font is not available.

On OSX there are no such warnings and the output seems correct:

enter image description here

However I am not sure why the pdf shows correctly in Chrome on Windows. Perhaps chromium includes extra fonts?

Jeroen Ooms
  • 30,444
  • 34
  • 124
  • 198
  • Thanks for the quick response Jeroen! I will try this as soon as I am back at my pc. – rdatasculptor Sep 05 '17 at 15:27
  • I will take a look tomorrow morning. The map was generated by `ggplot2`, I was not aware of this dingbat font. Maybe this issue is somehow related to this issue I published yesyerday: https://stackoverflow.com/q/46034457/1983395 – rdatasculptor Sep 05 '17 at 22:36
  • I looked ad my `ggplot2` code that generates te map. I only use `geom_point()` for the dots. I can't explain the dingbat font that the pdf comes up with. – rdatasculptor Sep 06 '17 at 07:54
  • Ah can you share the code to generate the map? Or at least something to reproduce the problem? Can you try to recreate the pdf with `pdf(... , useDingbats=FALSE)` – Jeroen Ooms Sep 06 '17 at 09:12
  • I am not sure it will help, I just use `geom_point(data = woonplaatsen,aes(x = lon, y = lat,group=personen,colour = groepsindeling),size = 0.8)` to produce the dots. and I use `ggsave()` to save it as a pdf. Using `pdftools` to produce a png file the dots are gone. BUT when I use `fig.path` parameter of a rmarkdown chunk to produce a pdf of the map, the dots are still there(!). – rdatasculptor Sep 07 '17 at 13:18
  • And `pdf_fonts()` gives no error when having used `fig.path` parameter of an R markdown chunk to produce the pdf. So that doesn`t seem to use dingbats fonts to produce the dots(?) – rdatasculptor Sep 07 '17 at 13:49
  • Oops, there still IS an error. So that doesn't explain the difference between the two kinds of ggplot to pdf to png conversions. – rdatasculptor Sep 07 '17 at 14:13
  • 2
    if you use ggsave you might need to set `pdf.options(useDingbats=FALSE)` first. – Jeroen Ooms Sep 07 '17 at 17:31
  • 2
    That solved it! If you add `pdf.options(useDingbats=FALSE)` to your answer I will be more than happy to accept it. Thanks a lot for your help! – rdatasculptor Sep 08 '17 at 08:01