How to save table background img original path+name in HTML

General TRichView support forum. Please post your questions here
Post Reply
vega
Posts: 50
Joined: Fri Oct 26, 2007 6:29 am

How to save table background img original path+name in HTML

Post by vega »

I could figure out how to include the original path & name of pictures into the exported HTML when rvActionInsertPicture1 is used to add a picture.

However, I still can't figure out how to do the same for tables/cells background images added through the table property dialog.

Please help in telling me what to change in the following proc. or provide a little code sample if another proc has to be used.

Code: Select all

procedure T_FrmRicardoCSS.RichViewEdit1HTMLSaveImage(
  Sender: TCustomRichView; RVData: TCustomRVData; ItemNo: Integer;
  const Path: String; BackgroundColor: TColor; var Location: String;
  var DoDefault: Boolean);

  var Filename: string;
begin
  if (ItemNo>=0) and
     RVData.GetItemExtraStrProperty(ItemNo, rvespImageFileName, FileName) and
     (FileName<>'') then begin
    Location := 'file:///' + FileName;
    DoDefault := False;
  end;
end;
Thanks in advance.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Your code work for table background.
For table cells:

Code: Select all

if (ItemNo=-1) and (RVData.GetSourceRVData is TRVTableCellData) then begin
  FileName := TRVTableCellData(RVData.GetSourceRVData).BackgroundImageFileName;
  if FileName<>'' then begin 
    Location := 'file://' + FileName; 
    DoDefault := False; 
  end;
end;
For the main document background, (ItemNo=-1) and not (RVData.GetSourceRVData is TRVTableCellData).
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

But I think you should check if FileName is a full local path (do not add 'file://' to relative paths and to internet addresses).
For example,

Code: Select all

if (Length(FileName)>=2) and (FileName[2]=':') then ...
vega
Posts: 50
Joined: Fri Oct 26, 2007 6:29 am

Post by vega »

Thank you for your reply Sergey.
You say :
<< Your code works for table background >>
but no, it doesn't. My code only works for pictures added through the rvActionInsertPicture1 action. This code does not respond to table background added through the Table Properties (right-click) - Background - Picture... option.

As for the Cell bg pic., the code you suggested (as follows)

Code: Select all

if (ItemNo=-1) and (RVData.GetSourceRVData is TRVTableCellData) then begin
  FileName := TRVTableCellData(RVData.GetSourceRVData).BackgroundImageFileName;
  if FileName<>'' then begin 
    Location := 'file://' + FileName; 
    DoDefault := False; 
  end;
end;
returns a compile error "EStringListError - Index out of bound (-1)".

Did I miss something ?

Thanks, Dan.
Last edited by vega on Thu Jan 10, 2008 6:56 am, edited 1 time in total.
vega
Posts: 50
Joined: Fri Oct 26, 2007 6:29 am

Post by vega »

Sergey Tkachenko wrote:But I think you should check if FileName is a full local path (do not add 'file://' to relative paths and to internet addresses).
For example,

Code: Select all

if (Length(FileName)>=2) and (FileName[2]=':') then ...
I use only absolute path to image files in my exported HTML. Compliant browsers (Firefox, Opera etc.) require "file:///" or "file://localhost/" before the local file path+filename or they will not display the picture. Only IE6 accepts a minimal path like "c:/xyz/w.jpg", which is not normal. However, IE will also recognize and display the image if "file:///C:/xyz/w.jpg" is provided so I add the file:/// thing to make sure that the html is viewable locally with any browser.

This is just a browser related issue and I suggest we forget about it since it is not TRV related.

Cheers, Dan
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you use this code:

Code: Select all

procedure TForm3.RichViewEdit1HTMLSaveImage(Sender: TCustomRichView;
  RVData: TCustomRVData; ItemNo: Integer; const Path: String;
  BackgroundColor: TColor; var Location: String; var DoDefault: Boolean);
var FileName: String;
begin
  if (ItemNo>=0) and
     RVData.GetItemExtraStrProperty(ItemNo, rvespImageFileName, FileName) and
     (FileName<>'') then begin
    Location := 'file:///' + FileName;
    DoDefault := False;
  end;
  if (ItemNo=-1) and (RVData.GetSourceRVData is TRVTableCellData) then begin
    FileName := TRVTableCellData(RVData.GetSourceRVData).BackgroundImageFileName;
    if FileName<>'' then begin
      Location := 'file:///' + FileName;
      DoDefault := False;
    end;
  end;
end;
I cannot reproduce EStringListError.

RichViewAction for table property does not assign file names for background pictures. This feature will be added in the next update.
vega
Posts: 50
Joined: Fri Oct 26, 2007 6:29 am

Post by vega »

Sergey Tkachenko wrote:Do you use this code:

Code: Select all

procedure TForm3.RichViewEdit1HTMLSaveImage(Sender: TCustomRichView;
  RVData: TCustomRVData; ItemNo: Integer; const Path: String;
  BackgroundColor: TColor; var Location: String; var DoDefault: Boolean);
var FileName: String;
begin
  if (ItemNo>=0) and
     RVData.GetItemExtraStrProperty(ItemNo, rvespImageFileName, FileName) and
     (FileName<>'') then begin
    Location := 'file:///' + FileName;
    DoDefault := False;
  end;
  if (ItemNo=-1) and (RVData.GetSourceRVData is TRVTableCellData) then begin
    FileName := TRVTableCellData(RVData.GetSourceRVData).BackgroundImageFileName;
    if FileName<>'' then begin
      Location := 'file:///' + FileName;
      DoDefault := False;
    end;
  end;
end;
Yes, I do use this code (I copied and pasted your code). Stepping thru it, I noticed that when ItemNo=-1 (cell bg img.), FileName = ''. Therefore, Location and DoDefault are never processed...

Sergey, my suggestion is the following: putting up a simple demo comprising a table with 1 row and 2 cols with a different background image in each cell, remembering that, when exported to HTML (CSS), the absolute path to the images should look like C:/xyz/w.jpg. In my opinion, this would solve the matter for many of us.

The other solution would be to let me know how to disable the [Picture...] buttons for tables and cells in the Table Properties dialog, so that the user doesn't set things that he can't see in the exported HTML when absolute path to image is used :roll:

In any case, the exporting to HTML capabilities of your component are amazing and with no doubt the best available on the market. Thanks for it!
Post Reply