Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Displaying RTF string to browser

by ikkon (Monk)
on Aug 21, 2007 at 17:05 UTC ( #634133=note: print w/ replies, xml ) Need Help??


in reply to Re: Displaying RTF string to browser
in thread Displaying RTF string to browser

I tried

$fh->close(); print STDOUT $RTF_obj;
and once the file opens in word I get a error document name or path is not valid


Comment on Re^2: Displaying RTF string to browser
Download Code
Replies are listed 'Best First'.
Re^3: Displaying RTF string to browser
by bart (Canon) on Aug 21, 2007 at 17:08 UTC
    That's a start. But you're printing the file name, not the file contents.

    Try, hmm... How to make this easy? OK, let's stick to general cross-platform solution: RTF is text, so we'll just print the text of the file to STDOUT line by line.

    open IN, $RTF_obj or die "Oops?"; while(<IN>) { print; }
      ok, tried that, and a few variations, I don't get a error so thats a plus, but I get a blank RTF not sure why though. not to familuar with creating streaming rtf.
        I installed RTF::Writer just to test your code, and after some edits I could make it compile. (For some reason, add_bgcolor isn't a recognized method, so I commented those out; and the use of your private module at the top too.)

        I initially got a blank file too. Then I noticed you have mixed two alternatives, you have to use either

        $fh = RTF::Writer->new_to_file($rtfReport);
        or
        $fh = RTF::Writer->new_to_string(\$RTF_obj);
        but not both. Don't mix them.

        For this application, it makes most sense to use the $RTF_obj, because it holds the entire RTF document in memory.

        And delete the line

        $fh->print(\$RTF_obj);
        near the end, it makes the document exactly twice as long and worse, it corrupts it as Word can no longer read it.

        So: near the top, just use

        $fh = RTF::Writer->new_to_string(\$RTF_obj);
        you'd even better delete every mention of $rtfReport; and near the bottom, right under $fh->close();, add
        print $RTF_obj;

        That's it. Drop the code I gave you earlier to read out the contents of the file, as there is no longer a file, you don't need it. Instead, you're printing out the contents of a string.

        HTH.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://634133]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2015-07-28 11:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (254 votes), past polls