Skip to contents

Overview

r2rtf provides multiple ways to convert RTF format to other formats including PDF, DOCX, and HTML:

  1. User-facing functions: write_docx() and write_html() - Exported functions for converting RTF encoding to DOCX or HTML
  2. 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 format argument allows you to specify output format as pdf, docx, or html.
r2rtf:::rtf_convert_format(input = "rtf/ae_example.rtf", format = "html")

Limitations

There is one known limitation after RTF file convert to HTML files:

  • table border issue.
    • “dash”, “small dash”, “dot dash”, and “dot dot” border type are not supported

Summary of Border Type Using Top Border

Border Type


single

double

dot

dash

small dash

dot dash

dot dot