Skip to content

Instantly share code, notes, and snippets.

@heaths
Created September 18, 2021 16:10
Show Gist options
  • Save heaths/123ca78c77cd1f2f8a6e07df4d6d2b62 to your computer and use it in GitHub Desktop.
Save heaths/123ca78c77cd1f2f8a6e07df4d6d2b62 to your computer and use it in GitHub Desktop.
Script to convert simple text e.g. LICENSE.txt to basic RTF for display in a RichEdit2.0 control
[CmdletBinding()]
param (
[Parameter(Mandatory=$true, Position=0)]
[string] $Path,
[Parameter(Mandatory=$true, Position=1)]
[string] $OutFile,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $FontFamily = 'Arial'
)
$rtf = "{\rtf1\ansi\deff0{\fonttbl{\f0\fcharset0 $FontFamily;}}\pard\sa200\sl200\slmult1\fs20`n"
foreach ($line in (Get-Content $Path)) {
if (!$line) {
$rtf += "\par`n"
} else {
$rtf += "$line`n"
}
}
$rtf += '}'
$rtf | Set-Content $OutFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment