RtfPipe icon indicating copy to clipboard operation
RtfPipe copied to clipboard

python - pythonnet doesn't work

Open kklem0 opened this issue 2 years ago • 0 comments

This can be a bug report or a future note for how to use it with pythonnet.

If you use it directly you'll get even if you use System.String

TypeError: No method matches given arguments for Rtf.ToHtml: (<class 'str'>)

Instead load it into RtfSource first with System.IO.StringReader then it works.

import clr
clr.AddReference('/Users/me/RtfPipe.dll')
import RtfPipe
import System

test = '{\pard test \par}'
net_string = System.String(test)
string_reader = System.IO.StringReader(net_string)
rtf_source = RtfPipe.RtfSource(string_reader)
html_output = RtfPipe.Rtf.ToHtml(rtf_source)
print(html_output)

kklem0 avatar Aug 29 '23 11:08 kklem0