RtfParser (rtf_parser v1.0.0)

RtfParser is a package that can be used to parse a RTF document.

This module contains two functions:

  • scan/1 scans the given RTF document and returns a list of tokens.
  • parse/1 parses the given list of tokens and returns a structured RTF document.

To following example shows the basic usage of the RtfParser package:

rtf = "{\rtf1\ansi\ansicpg1252\deff0\nouicompat\deflang1033{\fonttbl{\f0\fnil\fcharset0 Calibri;}}
{\*\generator Riched20 10.0.18362}\viewkind4\uc1 
\pard\sa200\sl276\slmult1\f0\fs22\lang9 This is a \b RTF document\b0 with some more text\par
}
"
{:ok, tokens} = RtfParser.scan(rtf)
{:ok, document} = RtfParser.parse(tokens)
IO.inspect(document)

Link to this section Summary

Functions

This function parses the given list of tokens and returns a structured RTF document.

This function scans the given RTF document and returns a list of tokens. These tokens represent the RTF document in a structured way.

Link to this section Functions

@spec parse([map()]) :: RtfDocument.t()

This function parses the given list of tokens and returns a structured RTF document.

The structured RTF document is represented as a RtfDocument struct.

The RtfDocument contains a Header struct and a list of StyleBlock structs. A StyleBlock struct contains all information about the formatting of a specific block of text. It contains a Painter struct and a Paragraph struct. Lastly it contains the actual text of the block.

@spec scan(binary()) :: [map()]

This function scans the given RTF document and returns a list of tokens. These tokens represent the RTF document in a structured way.