in reply to Re: How to print a text document to RTF document
in thread How to print a text document to RTF document

Sorry yeah the other post helped me out but I realized i need to convert it to text to sort it. Now I am having trouble writing it to an RTF file from text and changing the font color. The documentation with the colors is not very clear. Would you happen to know about this? I got it to the font i want but the colors will not work for me.

 $rtf->printf( \'{\fs30\lang1036\noproof %s} \par ', "$_\n");

Again, Thanks for all your help!

Replies are listed 'Best First'.
Re^3: How to print a text document to RTF document
by poj (Abbot) on Jul 10, 2017 at 16:19 UTC

    Red and blue are defaults, for other colors you have to define a color table

    #!/usr/bin/perl use strict; use RTF::Writer; my $output = 'c:/temp/colortext.rtf'; my $rtf = RTF::Writer->new_to_file($output); $rtf->prolog( 'title' => "Color Test", 'colors' => [ undef, [255,0,0], # 1-red [0,255,0], # 2-green [0,0,255], # 3-blue [255,128,0], # 4-orange ], ); $rtf->paragraph( \'\cf1',"This is Red" ); $rtf->paragraph( \'\cf2',"This is Green" ); $rtf->paragraph( \'\cf3',"This is Blue" ); $rtf->paragraph( \'\cf4',"This is Orange" ); $rtf->close;

      How do you use one of these colors as the background color?

      Thanks guys!

      So I went to test out the orange and it printed red. Any idea why? I use the code above

        This is the document output, looks OK to me in Word and OpenOffice. What does it print for you ?

        {\rtf1\ansi\deff0{\fonttbl {\f0 \froman Times New Roman;} } {\colortbl ;\red255\green0\blue0;\red0\green255\blue0;\red0\green0\blu +e255;\red255\green128\blue0;} {\info {\creatim \yr2017\mo7\dy10\hr17\min20\sec45} {\revtim \yr2017\mo7\dy10\hr17\min20\sec45} {\title Color Test} {\doccomm written by rtf1\'2epl [Perl RT\'46::Writer v1\'2e11]} } {\pard \cf1 This is Red \par} {\pard \cf2 This is Green \par} {\pard \cf3 This is Blue \par} {\pard \cf4 This is Orange \par} }
Re^3: How to print a text document to RTF document
by thanos1983 (Parson) on Jul 10, 2017 at 15:41 UTC

    Hello again mdavies23,

    No problem no worries. This is the reason that we need to have a valid input file/data so we can test based on your data and your expected output.

    Provide us a few lines of input, and the font/color that you get so we can experiment. I am not an expert with RTF files but I could play around if I have more data.

    Helps us to help you, BR.

    Seeking for Perl wisdom...on the process of learning...not there...yet!

      Here is a couple lines from the input file. I am trying to get it to output in red font.

      1254.252 Error

      1547.585 Warning

      15878.252 Error