Robert,

Thanks for the code. I tried to tweak it around the 1024-char limitation:

> sub btnChange_Click {
>     my $text1 = $re->Text();
>     my $maxlen = 1024;

I changed that to:
    my $maxlen = 2+ 2 * length $text1;

and left everything else the same. The problem now is that there is a
limitation to around 32k.


Here is the code I worked out, saving to a temporary file, but there
still is the limitation of 32k. Is there a way to work around this?

sub re_text($;$) {
    my ($re, $newtext) = shift;
    use File::Temp;
    my $tmp = File::Temp::mktemp('rtfXXXX');
    if (defined $newtext) {
        open my $file, '>:utf8', $tmp or die $!;
        print $tmp $newtext; close $file;
        $re->Load($tmp, 0x0020 | 0x0001 | 65001 << 16);  #
SF_USECODEPAGE | SF_TEXT | CP_UTF8
        0 while unlink $tmp;
        return 1;
    } else {
        $re->Save($tmp, 0x0020 | 0x0001 | 65001 << 16);  #
SF_USECODEPAGE | SF_TEXT | CP_UTF8
        open my $file, '<:utf8', $tmp or die $!;
        local $/ = undef; $_ = <$file>; close $file; 0 while unlink $tmp;
        return $_;
    }
}

Thanks,
Dan

Reply via email to