Does BIRT recognize RTF tags?

65 Views Asked by At

I have a dataset that returns a BLOB field (thats how BIRT has binded in the table). In the database the data type is classified as Long Raw, so i need to transform the binary data to text using a generic convert function.

The problem is that BIRT appears to not recognize embedded RTF expressions after the conversion, but maybe im doing something wrong.

I was using a Dynamic Text component that contains the data converted in the Expression Builder property. Also, the content type of that field is set to RTF.

Here is how BIRT shows

{\rtf1\ansi
\ansicpg1252\deff0{\fonttbl{\f0\fnil MS
Sans Serif;}{\f1\fnil\fcharset0 MS Sans
Serif;}}
\viewkind4\uc1\pard\qc\lang1046\b
\f0\fs16 1 x\f1\'ed\-cara de leite
\par 1 colher de sopa de fermendo em p
\'f3
\par 3 x\'ed\-caras de farinha de trigo
\par 3 x\'ed\-caras de a\'e7\'facar
\par 3 ovos
\par 4 colheres de margarina\b0\f0
\par }

As we can see, the text contains RTF tags mixed with the main content.

The idea is to make birt delete the tags or be able to model them in some way.

Here is how i was expecting the output

1 xícara de leite
1 colher de sopa de fermento
3 xícaras de farinha de trigo
2

There are 2 best solutions below

0
Davi Emediato On

After some research there is a possible answer, but is not the perfect one because the goal was to model in some way the RTF tags. Here it is:

The firs step os to convert the binary data

function convert( byteArr ) {
  const convertedbyteArr = "";
  for(var i = 0; i<byteArr.length;i++){
    teste += String.fromCharCode(byteArr[i]);
  }
  return convertedbyteArr ;
}

The next step is to delete all RTF tags using regex. This solution was based on this post: Regular Expression for extracting text from an RTF string .

function removeRTF (str) {
    var basicRtfPattern = /\{\*?\\[^{}]+;}|[{}]|\\[A-Za-z]+\n?(?:-?\d+)?[ ]?/g;
    var newLineSlashesPattern = /\\\n/g;
    var ctrlCharPattern = /\n\\f[0-9]\s/g;

    return str
    .replace(ctrlCharPattern, "")
    .replace(basicRtfPattern, "")
    .replace(newLineSlashesPattern, "\n")
    .replace(/\\'c9/g,"É")
    .replace(/\\'cd/g,"Í")
    .replace(/\\'ed\\-/g,"í")
    .replace(/\\'f3/g,"ó")
    .replace(/\\'d3/g,"Ó")
    .replace(/\\'fa/g,"ú")
    .replace(/\\'fa/g,"ú")
    .replace(/\\'da/g,"Ú")
    .replace(/\\'e7/g,"ç")
    .replace(/\\'e1/g,"á")
    .replace(/\\'e1/g,"á")
    .replace(/\\'e0/g,"à")
    .replace(/\\'c0/g,"À")
    .replace(/\\'c1/g,"Á")
    .trim();
}

It is important to note that the accents are treated individually.

0
hvb On

The old ROM specification of BIRT shows that once upon a time there were plans to support RTF formatted text, but it was never implemented (and never will be implemented).

The de-facto standard for formatted text coded in a text file is now HTML.