Overview
r2rtf provides multiple ways to convert RTF format to
other formats including PDF, DOCX, and HTML:
-
User-facing functions:
write_docx()andwrite_html()- Exported functions for converting RTF encoding to DOCX or HTML -
Internal function:
r2rtf:::rtf_convert_format()- Lower-level function for batch conversion of RTF files
All conversion features require LibreOffice >= 7.1 and currently support Unix/Linux/macOS systems only.
Using write_docx() and write_html()
The write_docx() and write_html() functions
provide a simple interface to convert RTF encoding directly to DOCX or
HTML formats.
Write DOCX
# Create RTF encoding
rtf <- head(iris) |>
rtf_body() |>
rtf_encode()
# Convert to DOCX
write_docx(rtf, "output/table.docx")Write HTML
# Create RTF encoding
rtf <- head(cars) |>
rtf_body() |>
rtf_encode()
# Convert to HTML
write_html(rtf, "output/table.html")Using rtf_convert_format() (Advanced)
The internal r2rtf:::rtf_convert_format() function
provides more control for batch processing of existing RTF files.
By default, r2rtf:::rtf_convert_format converts RTF
files to PDF format. The PDF file will be saved in the same folder with
same file name by default.
In the example below, ae_example.pdf will be created in
the same folder.
r2rtf:::rtf_convert_format(input = "rtf/ae_example.rtf")- Multiple files can be provided as input.
r2rtf:::rtf_convert_format(input = list.files("rtf", pattern = "*.rtf"))- The
formatargument allows you to specify output format aspdf,docx, orhtml.
r2rtf:::rtf_convert_format(input = "rtf/ae_example.rtf", format = "html")