I have been able to tokenize a RTF document and then print it to another RTF document. My question is whether or not it is possible to keep the original formatting from the first document (font, font color, background color). There are somethings that are randomly colored in the document so keeping the formatting is important.

Here it the tokenizer code

#!usr/bin/perl use strict; use warnings; use RTF::Writer; use Data::Dumper; use RTF::Tokenizer; die "usage: $0 input output\n" unless @ARGV == 2; my $infile = shift; my $outfile = shift; my $tokenizer = RTF::Tokenizer->new(); $tokenizer->read_file($infile); my ( $token_type, $argument, $parameter ); { # reduce bogus warnings no warnings 'uninitialized'; # get past the header ( $token_type, $argument, $parameter ) = $tokenizer->get_token() until ($token_type eq 'control' and $argument eq 'par'); } my @final; while ($token_type ne 'eof'){ ( $token_type, $argument, $parameter ) = $tokenizer->get_token(); push @final, $argument if $token_type eq 'text'; } my $rtf = RTF::Writer->new_to_file($outfile); my @sorted = sort { my @fields_a = split / / , $a; my @fields_b = split / /, $b; chomp($a, $b); $fields_a[0] cmp $fields_b[0]; } @final; $rtf->prolog; $rtf->print(\@sorted); $rtf->close;

In reply to Keeping RTF formatting when moving files by mdavies23

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.