Created
September 18, 2021 16:10
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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