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

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;

Replies are listed 'Best First'.
Re^4: How to print a text document to RTF document
by mdavies23 (Acolyte) on Jul 11, 2017 at 11:16 UTC

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

        I am trying to get the background black, all the other ones work and when i put in chcbpat0 or chcbpatN it just gives me a white background

Re^4: How to print a text document to RTF document
by mdavies23 (Acolyte) on Jul 10, 2017 at 16:42 UTC

    Thanks guys!

Re^4: How to print a text document to RTF document
by mdavies23 (Acolyte) on Jul 10, 2017 at 16:58 UTC

    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} }

        I got it to work. Thanks!