Export images to RTF

General TRichView support forum. Please post your questions here
Post Reply
eini
Posts: 2
Joined: Tue Jun 25, 2013 7:25 pm

Export images to RTF

Post by eini »

Hi,

I'm using an TrichViewEdit and trying to export RTF with embedded images,
but after exporting, the resulting RTF seems to contain non-standard-conform images.
Opened in WordPad or MS-Word all looks fine, but with Openoffice or importet to a TRichView all images are broken or missing.
Thats very unfortunate, because i can't exchange data between a RichViewEdit and a RichView without losing all images.

Is there any solution? Do I miss any options?

Here is some example code, a full project can be provided if necessary.

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
  procedure InsertBitmap(re: TRichViewEdit; aBmp : TBitmap);
  var
    bmp : TBitmap;
  begin
    bmp := TBitmap.Create;
    try
      bmp.Width := aBmp.Width;
      bmp.Height := aBmp.Height;
      bmp.Canvas.Draw(0, 0, aBmp);

      re.AddPictureEx('', bmp, -1, rvvaBaseline);
    finally
      //Freed by RichView
    end;
  end;
begin
  //Build up data
  RichViewEdit1.Clear;
  RichEdit1.Clear;
  RichViewEdit1.AddNL('Here is the Image:', 0, 0);
  InsertBitmap(RichViewEdit1, Image1.Picture.Bitmap);
  RichViewEdit1.Format;

  //Copy to RichEdit
  CopyToRichEdit();
  //Now all images are missing in RichEdit1
end;

procedure TForm1.CopyToRichEdit();
var
  strm : TMemoryStream;
begin
  strm := TMemoryStream.Create;
  try
    RichViewEdit1.SaveRTFToStream(strm, false);
    strm.Position := 0;
    RichEdit1.Lines.LoadFromStream(strm);
  finally
    strm.Free;
  end;
end;
[/code]
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) As for TRichEdit, as far as I know, it cannot load any image from RTF
2) By default, TRichView saves TBitmap images in RTF as \dibitmap. This is an absolutely valid way to save images, but as you can see, OpenOffice does not understand it.
If you enabled support of PNG images (in new version of TRichView, it is enabled automatically for Delphi 2009+), you can save bitmaps as PNG: include rvrtfPNGInsteadOfBitmap in RichViewEdit1.RTFOptions. RTF with PNG is understood by OpenOffice Writer.
eini
Posts: 2
Joined: Tue Jun 25, 2013 7:25 pm

Post by eini »

Sergey Tkachenko wrote:1) As for TRichEdit, as far as I know, it cannot load any image from RTF
:shock: you are right.
I'm embedding bitmaps to RichEdits for a long time now, but never noticed, that the images are gone after storing and loading with streams/files.
Anyway, I'm trying to find another solution for my problem.

Thanks for your answer!
Post Reply