docx_embed_font: Embed Fonts in a Word Document

View source: R/docx_embed_font.R

docx_embed_fontR Documentation

Embed Fonts in a Word Document

Description

Copy TrueType or OpenType font files from the local system into a Word document. The font data is stored inside the .docx archive so that the document renders correctly when opened on a system where the font is not installed.

When only font_family is provided (without regular), the function looks up font file paths on the local system via gdtools::sys_fonts() and copies them into the document. A message shows the equivalent explicit call for reproducibility.

Usage

docx_embed_font(
  x,
  font_family,
  regular = NULL,
  bold = NULL,
  italic = NULL,
  bold_italic = NULL
)

Arguments

x

an rdocx object

font_family

font family name as it will appear in the document. When regular is not provided, this name is used to look up font files via gdtools::sys_fonts().

regular

path to the regular .ttf/.otf font file. If NULL, font files are detected automatically via gdtools.

bold

path to the bold .ttf/.otf font file (optional)

italic

path to the italic .ttf/.otf font file (optional)

bold_italic

path to the bold-italic .ttf/.otf font file (optional)

Value

the rdocx object with embedded fonts

Font licensing

Embedding a font in a document redistributes it. You must ensure that the font license permits embedding. Fonts under the SIL Open Font License (e.g. Liberation, Google Fonts) generally allow it. Many commercial fonts restrict or prohibit embedding. Check the license of the font before using this function.

See Also

gdtools::sys_fonts(), gdtools::register_gfont(), docx_set_settings()

Examples


# automatic detection (requires gdtools)
gdtools::register_liberationsans()
doc <- read_docx()
doc <- docx_embed_font(doc, font_family = "Liberation Sans")

# # explicit paths (no gdtools needed)
# doc <- docx_embed_font(
#   doc,
#   font_family = "My Font",
#   regular = "path/to/font-regular.ttf",
#   bold = "path/to/font-bold.ttf"
# )


officer documentation built on April 24, 2026, 5:06 p.m.