You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在R语言中使用Verdana字体生成PDF文件的技术问题

解决R生成PDF时使用Verdana字体的问题

Got it, let's get your Verdana font working in your R-generated PDFs smoothly. Since you've confirmed the font is already installed locally (and shows up in fonts()), here's what you need to do:

  • 第一步:安装并加载字体管理包
    R's base pdf() function can be finicky with system fonts, so we'll use the extrafont package to bridge the gap. Install and load it first:

    install.packages("extrafont")
    library(extrafont)
    
  • 第二步:注册Verdana到R的字体库
    Run these commands to make R recognize your local Verdana font (you only need to do this once—after that, the font will stay available even if you restart R):

    font_import(pattern = "Verdana") # Target only Verdana to speed up the process
    loadfonts(device = "pdf") # Load the font specifically for PDF output
    
  • 第三步:生成PDF with Verdana
    Now you can directly specify family = "Verdana" in your pdf() call, just like you did with Helvetica:

    pdf("abc.pdf", height = 11, width = 8.5, family = "Verdana")
    # Add your plotting/output code here, e.g.:
    plot(1:10, main = "This Title Uses Verdana!")
    dev.off()
    
  • Alternative: Use cairo_pdf() if you hit snags
    If the base pdf() method doesn't work for your system, cairo_pdf() has better native support for system fonts. Try this instead:

    cairo_pdf("abc_cairo.pdf", height = 11, width = 8.5, family = "Verdana")
    plot(1:10, main = "Verdana via Cairo PDF")
    dev.off()
    

A quick note: font_import() might take a minute to run—if you omit the pattern argument, it will import all your system fonts, but targeting just Verdana saves time. Also, make sure you're running a relatively recent version of R to avoid compatibility hiccups.

内容的提问来源于stack exchange,提问作者Vik G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 07:03:18