Skip to content

Commit aa03cce

Browse files
1. RTF2PlainWordpad added
1 parent 5414631 commit aa03cce

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

RTFParse/Main.rvl.xlsx

207 Bytes
Binary file not shown.

RTFParse/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ This function works with simple RTFs only, i.e.:
1515

1616

1717
```javascript
18-
function CompareWithRTF(/**string*/rtfPath, /**string*/expectedText, /**string*/message)
18+
function CompareWithRTF(/**string*/rtfPath, /**string*/expectedText, /**string*/message, /**boolean*/useWordpad)
1919
```
20-
Compare text in RTF file and add an assertion with specified message.
20+
Compare text in RTF file and add an assertion with specified message. If last parameter (useWordpad) is specified then conversion is performed using `RTF2PlainWordpad`.
21+
22+
23+
```javascript
24+
function RTF2PlainWordpad(/**string*/rtfPath)
25+
```
26+
Same as `RTF2Plain` but it is slower and can handle advanced and RTF files with pictures and heavy formatting.
27+
2128

2229
## Usage
2330

RTFParse/User.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//Put your custom functions and variables in this file
22

33

4-
5-
64
function RTF2Plain(/**string*/rtfPath)
75
{
86
// https://stackoverflow.com/questions/29922771/convert-rtf-to-and-from-plain-text
@@ -27,13 +25,33 @@ function RTF2Plain(/**string*/rtfPath)
2725
return plainText;
2826
}
2927

28+
function RTF2PlainWordpad(/**string*/rtfPath)
29+
{
30+
Global.DoLaunch('wordpad.exe "'+rtfPath+'"')
31+
Global.DoSleep(1000);
32+
Global.DoSendKeys('^a')
33+
Global.DoSleep(100);
34+
Global.DoSendKeys('^c')
35+
Global.DoSleep(100);
36+
Global.DoSendKeys('%{F4}');
37+
var res = Global.GetClipboardText();
38+
res = Global.DoTrim(res);
39+
Log(rtfPath+" text: \n"+res);
40+
return res;
41+
}
3042

31-
function CompareWithRTF(/**string*/rtfPath, /**string*/expectedText, /**string*/message)
43+
function CompareWithRTF(/**string*/rtfPath, /**string*/expectedText, /**string*/message, /**boolean*/useWordpad)
3244
{
33-
var rtfPlain = RTF2Plain(rtfPath);
45+
if(useWordpad)
46+
{
47+
var rtfPlain = RTF2PlainWordpad(rtfPath);
48+
} else {
49+
var rtfPlain = RTF2Plain(rtfPath);
50+
}
3451

3552
message = message || expectedText;
3653

3754
Tester.AssertEqual(message, rtfPlain, expectedText);
3855
return rtfPlain;
39-
}
56+
}
57+

0 commit comments

Comments
 (0)