View source: R/docx_embed_font.R
| docx_embed_font | R Documentation |
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.
docx_embed_font(
x,
font_family,
regular = NULL,
bold = NULL,
italic = NULL,
bold_italic = NULL
)
x |
an rdocx object |
font_family |
font family name as it will appear in the document.
When |
regular |
path to the regular .ttf/.otf font file. If |
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) |
the rdocx object with embedded fonts
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.
gdtools::sys_fonts(), gdtools::register_gfont(),
docx_set_settings()
# 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"
# )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.