Page 1 of 2

Convert richview files to rtf

Posted: Thu Jul 21, 2016 7:53 am
by borax1974
Hi,

I'm a Delphi developer but not a user of RichView components. I came across a database of files with TRichView's format. I have to convert these files to rtf (more than 10.000 files).

Any recommendations, command line tools etc to convert them?

Best regards

Bora Aydemir

Posted: Thu Jul 21, 2016 9:20 pm
by Sergey Tkachenko
Do you need to convert all files in some directory?

Posted: Fri Jul 22, 2016 6:30 am
by borax1974
They are stored in a database. I will fetch, convert and store it to my database. I need help with the converting (to rtf) process. A command line tool would help. Or can I do it with the trial version of the component?

I have Delphi Seattle Prof.

Posted: Fri Jul 22, 2016 2:47 pm
by Sergey Tkachenko
Do you want to store in the same database?
It's simple: TDBRichViewEdit autodetects the field format, and saves to format specified in FieldFormat property.

So, if you want to convert all the fields, you can use the code below.

Let:
Table is a data set containing documents.
DBRVE is TDBRichViewEdit linked to this table.

Code: Select all

DBRVE.AutoDeleteUnusedStyles := True;
DBRVE.FieldFormat := rvdbRTF;
Table.First;
while not Table.EOF do
begin
  Table.Edit;
  DBRVE.Change;
  Table.Post;
  Table.Next;
end;

Posted: Mon Jul 25, 2016 7:41 am
by borax1974
Thanks Sergey,

Will I be needing a registered version for this code to run?

Posted: Mon Jul 25, 2016 11:35 am
by Sergey Tkachenko
No, a trial version can be used.

Re: Convert richview files to rtf

Posted: Thu Jun 29, 2017 2:51 pm
by edward
Sergey,

I'm using TRichView with Delphi 2007 and saving data directly in firebird 2.5 blobs. I don't use dbware components. Now, I need to convert all blobs to the Seatle version, with unicode support. There is any easy way?

Best regards,

Edward

Re: Convert richview files to rtf

Posted: Thu Jun 29, 2017 6:58 pm
by Sergey Tkachenko
I do not think that conversion is needed, if you continue using TRichView.
The component can read document saved by older versions

What's the format of documents?

1) If RTF
There is no need to do something with existing RTF documents.
They will be loaded in Unicode, if TRichView.RTFReadProperties.UnicodeMode = rvruOnlyUnicode.
There is no need to change format of the field containing RTF to Unicode: all what you get is increased data size (twice). RTF is able to contain Unicode characters even when stored in ANSI field.

2) If RVF
RVF should be stored in a binary field, allowing any type of data. It must not be stored in Unicode memo field.
RVF documents are loaded as they are, so if they contained non-Unicode text, it will be non-Unicode after loading.
So, after loading, you should convert text to Unicode, see ConvertToUnicode from http://trichview.com/forums/viewtopic.p ... 569#p11569

Re: Convert richview files to rtf

Posted: Mon Jul 24, 2017 1:48 pm
by edward
Hi Sergey,

The RVF content stored in blob field is loaded correctly but I use fields to fill data in document, in runtime. At this moment, the content of all fields are being showed in the editor correctly, but not in the print preview. If I edit the document, the characters are transformed to "chinese characters".

I did see when the editor inserts the line feed at any position of this text inserted by tag, it is changed by chinese characters too.

Do you have any idea?
Best regards

Edward
print_preview.png
print_preview.png (20.49 KiB) Viewed 38776 times
editor.png
editor.png (7.24 KiB) Viewed 38776 times

Re: Convert richview files to rtf

Posted: Mon Jul 24, 2017 6:06 pm
by Sergey Tkachenko
How do you insert these fields?

Re: Convert richview files to rtf

Posted: Mon Jul 24, 2017 6:53 pm
by edward
Hi, bellow is the code:

Code: Select all

procedure TfrEditor.FillFields(RVData: TCustomRVData);
  function ConvertStringToItemText(const Text: String;
    UnicodeItem: Boolean; CodePage: Cardinal): TRVRawByteString;
  begin
    if UnicodeItem then
      Result:=RVU_StringToRawByteString(Text,True,CodePage)
      Result := RVU_AnsiToUnicode(CodePage, Text)
    else
       Result := TRVAnsiString(Text);
  end;
var
  i, j, r, c: Integer;
  table: TRVTableItemInfo;
  FieldName{, FieldValue}: string;

  ParaNo: Integer;
  BR, ContinuePara, Unicode: Boolean;
  item: TRVTextItemInfo;
  CodePage: TRVCodePage;
  sr: TRVRawByteString;
  s,Value: String;
  StyleNo: Integer;
begin
  for i := 0 to ComponentCount - 1 do
    if (Components[i] is TdxBarButton) and (StrLeft(TdxBarButton(Components[i]).Name,8)='btF10Var') then
      TdxBarButton(Components[i]).Description:=TdxBarButton(Components[i]).Caption;
  for i := 0 to RVData.ItemCount - 1 do begin
   if RVData.GetItemStyle(i) = rvsTable then begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.Rows.Count - 1 do
        for c := 0 to table.Rows[r].Count - 1 do
          if table.Cells[r, c] <> nil then
            FillFields(table.Cells[r, c].GetRVData);
      table.Changed;
    end else if RVData.GetItemStyle(i) >= 0 then begin
      FieldName := RVData.GetItemTag(i);
      if AllTrim(FieldName)<>'' then begin
        LoadFields(FieldName); 
        ParaNo := RVData.GetItemPara(i);
        BR     := RVData.GetItem(i).BR;
        StyleNo:=RVData.GetItem(i).StyleNo;
        ContinuePara := RVData.GetItem(i).SameAsPrev;
        StyleNo:=RVData.GetItem(i).StyleNo;
        Value := GetFieldItem(FieldName).Description;
        RVData.DeleteItems(i,1);
        item := RichViewTextItemClass.Create(RVData);
        s := Value;
        item.ParaNo := ParaNo;
        item.StyleNo := StyleNo;
        CodePage := RVData.GetItemCodePage2(item);
        item.SameAsPrev := ContinuePara;
        item.BR         := BR;
        sr := ConvertStringToItemText(s, True, CodePage);
        item.Inserting(RVData, sr, False);
        RVData.Items.InsertObject(i, sr, item);
        item.Inserted(RVData,i);
      end;
    end;
  end;
end;

Re: Convert richview files to rtf

Posted: Mon Jul 24, 2017 6:54 pm
by edward

Code: Select all

// basicly to work with Unicode
sr := ConvertStringToItemText(s, True, CodePage);
item.Inserting(RVData, sr, False);
RVData.Items.InsertObject(i, sr, item);
item.Inserted(RVData,i);

function ConvertStringToItemText(const Text: String;
UnicodeItem: Boolean; CodePage: Cardinal): TRVRawByteString;
begin
  if UnicodeItem then
    Result:=RVU_StringToRawByteString(Text,True,CodePage)
  else
    Result := TRVAnsiString(Text);
end;

Re: Convert richview files to rtf

Posted: Mon Jul 24, 2017 6:58 pm
by edward
If the entire content of the field fits in to the screen, without a line break, works fine. When the field cause a line break, ou either, the content is edited, the chinese character apears in the text. The format in database is RVF. The blob field is saved in a temp file and the file is loaded to the richedit. All its process is working fine. Only my "macro" fields, is wrong.

Best regards
Edward

Re: Convert richview files to rtf

Posted: Mon Jul 24, 2017 7:12 pm
by edward
Firebird 3.0
Character Set WIN1252

Re: Convert richview files to rtf

Posted: Tue Jul 25, 2017 1:03 pm
by edward
Sergey, the problem was solved:

Code: Select all

  function ConvertStringToItemText_(const Text: String; UnicodeItem: Boolean; CodePage: Cardinal): TRVRawByteString;
  begin
    if UnicodeItem then
      Result := RVU_GetRawUnicode(Text)
    else
      Result := TRVAnsiString(Text);
  end;

  function ConvertStringToItemText(const Text: String; RVData: TCustomRVData; StyleNo: Integer): TRVRawByteString;
  begin
    Result := ConvertStringToItemText_(Text, RVData.GetRVStyle.TextStyles[StyleNo].Unicode, RVData.GetStyleCodePage(StyleNo));
  end;


        sr := ConvertStringToItemText(s, RVData, StyleNo);
        if Editor.Style.TextStyles[item.StyleNo].Unicode then
          item.ItemOptions := item.ItemOptions+[rvioUnicode];

        item.Inserting(RVData, sr, False);
        RVData.Items.InsertObject(i, sr, item);
        item.Inserted(RVData,i);