I have created a program that takes in a RTF document, sorts it, and then outputs another RTF document. The problem is that the input file is around 400kb and the output file is 3000 kb. I noticed that the old RTF has the formatting stated at the top and the new RTF has the formatting attached to every line because I am looping through the array with all the text. Here is an example of the code:
my @warning_array; print "Enter input file (.RTF)\n"; $infile = <STDIN>; chomp($infile); print "Enter output file (.RTF)\n"; $outfile = <STDIN>; chomp($outfile); #Open selected files open my $fh, "<", $infile; open my $output, ">", $outfile; #New RTF writer my $rtf = RTF::Writer->new_to_file($outfile); no warnings 'uninitialized'; #New RTF -> text converter my $object = RTF::TEXT::Converter->new (output => \$string +); $object->parse_stream( $fh ); #Create the array and push the text into it my @un = split("\n", $string); #Sort the array my @sorted = sort { my @fields_a = split / / , $a; my @fields_b = split / /, $b; chomp($a, $b); $fields_a[1] cmp $fields_b[1] || $fields_a[0] <=> $field +s_b[0]; } @un; #SEARCH FOR WARNINGS @warning_array = grep {$_ =~ 'WARNING'} (@sorted); foreach(@warning_array){ if ($_ =~ "WARNING"){ $rtf->prolog( 'title' => "Color Test", 'colors' => [ undef, [0,0,0], # 1 - black [255,0,0], # 2-red [0,255,0], # 3-green [0,0,255], # 4-blue [255,128,0], # 5-orange [255,255,0], # 6-yellow ], ); #PRINT WARNINGS IN YELLOW $rtf->printf( \'{\fs20\lang1036\noproof\cf5\chshdn +g10000\chcbpatN\chcfpatN\cbN %s} \par ', "$_"); } } }
Is there any way to make the output smaller?
In reply to RTF size issues by mdavies23
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |