striprtf

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 4, 2024 License: MIT Imports: 13 Imported by: 0

README

striprtf

This package is based on IntelligenceX/fileconversion and J45k4/rtf-go.

striprtf is a Go package designed to extract plain text or HTML content from RTF (Rich Text Format) documents, removing all formatting information.

Installation

To install the package, use the go get command:

$ go get github.com/attilabuti/striprtf@latest

Usage

Here's a basic example of how to use the striprtf package:

Extracting text from RTF
package main

import (
    "fmt"
    "io"
    "os"

    "github.com/attilabuti/striprtf"
)

func main() {
    file, err := os.Open("document.rtf")
    if err != nil {
        panic(err)
    }
    defer file.Close()

    r, err := striprtf.ExtractText(file)
    if err != nil {
        panic(err)
    }

    text, err := io.ReadAll(r)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(text))
}
Extracting HTML from RTF
package main

import (
    "fmt"
    "io"
    "os"

    "github.com/attilabuti/striprtf"
)

func main() {
    file, err := os.Open("document.rtf")
    if err != nil {
        panic(err)
    }
    defer file.Close()

    r, err := striprtf.ExtractHtml(file)
    if err != nil {
        panic(err)
    }

    html, err := io.ReadAll(r)
    if err != nil {
        panic(err)
    }

    fmt.Println(string(html))
}

Issues

Submit the issues if you find any bug or have any suggestion.

Contribution

Fork the repo and submit pull requests.

License

This extension is licensed under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractHtml

func ExtractHtml(r io.Reader) (io.Reader, error)

ExtractHtml removes RTF formatting from HTML content provided via an io.Reader, returning the plain HTML as an io.Reader or an error if extraction fails.

func ExtractText

func ExtractText(r io.Reader) (io.Reader, error)

ExtractText reads RTF content from an io.Reader and returns the plain text without RTF formatting as an io.Reader, or an error if extraction fails.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL