Recover the Filename of Picture when Html Saving

General TRichView support forum. Please post your questions here
Post Reply
remixtech
Posts: 49
Joined: Mon Jun 18, 2007 3:53 pm

Recover the Filename of Picture when Html Saving

Post by remixtech »

Hello,

I would like to recover the filename of picture (background of a table)... and i don't know how to recover it...

This code showme the location of image in the document

Code: Select all

procedure Tf_ecriture.editeurHTMLSaveImage(Sender: TCustomRichView;
  RVData: TCustomRVData; ItemNo: Integer; const Path: string;
  BackgroundColor: TColor; var Location: string; var DoDefault: Boolean);
begin
showmessage('SaveImage : ' + location);
if location <> '' then      begin

    Location := '';
    DoDefault := False;
end;

end;
And to recover the filename of the picture in the table background, i am using this : But messagebox show me 'Saveimage2 : , ,'

How to recover the filename (and the location) of the picture ?

Code: Select all

procedure Tf_ecriture.editeurSaveImage2(Sender: TCustomRichView;
  Graphic: TGraphic; SaveFormat: TRVSaveFormat; const Path,
  ImagePrefix: string; var ImageSaveNo: Integer; var Location: string;
  var DoDefault: Boolean);
begin
  if SaveFormat = rvsfHTML then
  begin
  showmessage('SaveImage2 : ' + location+','+imageprefix+','+path);
    Location := '';
    DoDefault := False;
  end;
end;
Thanks a lot
remixtech
Posts: 49
Joined: Mon Jun 18, 2007 3:53 pm

Post by remixtech »

I had picture like this : (for the test)

Code: Select all

var
  lafenetre: tf_dlpicture;
  gr: TGraphic;
  pic: TPicture;
  generatefilename: string;
  fs: tfilestream;
begin
  randomize;
  lafenetre := tf_dlpicture.Create(self);
  try

    if lafenetre.ShowModal = mrOk then
    begin
      generatefilename := rightstr(lafenetre.ed_url.Text, length(lafenetre.ed_url.Text) - invpos('/', lafenetre.ed_url.text));

      while fileexists(f_principale.chemin + 'temp\' + generatefilename) do
        generatefilename := inttostr(random(10)) + generatefilename;

      try
        fs := tfilestream.Create(f_principale.chemin + 'temp\' + generatefilename, fmcreate);

        DownloadHTTP(lafenetre.ed_url.Text, tstream(fs));

      finally
        fs.Free;

      end;
      try
        pic := TPicture.Create;
        try

          pic.LoadFromFile(f_principale.chemin + 'temp\' + generatefilename);
          gr := RV_CreateGraphics(TGraphicClass(pic.Graphic.ClassType));
          gr.Assign(pic.Graphic);
        finally
          pic.Free;
          deletefile(f_principale.chemin + 'temp\' + generatefilename);
        end;
        if gr <> nil then
          editeur.InsertPicture(lafenetre.ed_url.text, gr, rvvaBaseLine);
      except
        Application.MessageBox(PChar('Cannot read picture from file.'), 'Error',
          MB_OK or MB_ICONSTOP);
      end;

    end;

  finally
    lafenetre.Free;
  end;
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

All these events occur BEFORE image saving. At this point, the location of the image is not defined yet.
Location is an output parameter in these events. In OnHTMLSaveImage, it is not empty only if vsoUseItemImageFileNames is included in the Options parameter of SaveHTML/SaveHTMLEx, and rvespImageFileName property of the image item is not empty.
There is no event occuring after the image saving, when Location is defined. If you want to know a list of images in this HTML, you need write code for saving pictures yourself in one of these events (you can use Sender.SavePicture method).

Can you explain what do you want to implement? I'll try to help.
remixtech
Posts: 49
Joined: Mon Jun 18, 2007 3:53 pm

Post by remixtech »

With trichviewaction i add some pictures on the documents, i add also other pictures from the web like this:

Code: Select all

editeur.InsertPicture(lafenetre.ed_url.text, gr, rvvaBaseLine); 
I would like to change all the filename or URL (because with this function i store URL) with Content id (i am developping a mail client)..

In the editeurHTMLSaveImage i recover the real url or filename, and i replace it to the real content id...

Exemple
Moon.jpg will become cid:djsgkjfdkjgdfs@onkeysoft in the html file
and i store in the attachment file moon.jpg

Have you understand ?

Thanks
remixtech
Posts: 49
Joined: Mon Jun 18, 2007 3:53 pm

Post by remixtech »

This is my function :

Code: Select all

function tf_ecriture.givemecid: string;
var
  buffer: string;
begin
  randomize;
  buffer := inttostr(random(9999999999)) + 'IMAIL' + inttostr(random(9999999999)) + '@onkeysoft';

  while liste_cid.IndexOf(buffer) <> -1 do
    buffer := inttostr(random(9999999999)) + 'IMAIL' + inttostr(random(9999999999)) + '@onkeysoft';

  result := buffer;
end;

procedure Tf_ecriture.editeurHTMLSaveImage(Sender: TCustomRichView;
  RVData: TCustomRVData; ItemNo: Integer; const Path: string;
  BackgroundColor: TColor; var Location: string; var DoDefault: Boolean);
var
  cid: string;
begin

  if location <> '' then
  begin

    location := trim(location);
    if uppercase(leftstr(location, 7)) <> 'HTTP://' then
    begin
     if liste_images.IndexOf(location) <>-1 then begin
              cid := liste_cid.Strings[liste_images.IndexOf(location)];

      Location := 'cid:' +cid;

     end else begin


      cid := givemecid;
      liste_images.Add(location);
      liste_cid.Add(cid);
      Location := 'cid:' +cid;

     end;


    end;

    DoDefault := False;
  end;

end;
remixtech
Posts: 49
Joined: Mon Jun 18, 2007 3:53 pm

Post by remixtech »

Hum after investigation :

I have found some solutions :

Code: Select all

  rvActionInsertPicture1.StoreFileName := true;
  rvActionTableProperties1.StoreImageFileName := true;

editeur.SetCurrentItemExtraStrProperty(rvespImageFileName,lafenetre.ed_url.text,true);
Do you have any other solutions ?
remixtech
Posts: 49
Joined: Mon Jun 18, 2007 3:53 pm

Post by remixtech »

Hum it's okay for a lot of thing, but for background... It is impossible to add a rvespImageFileName...

Is there a solution or must I implement it ?

Thanks a lot,
Sergey Tkachenko
Site Admin
Posts: 17566
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Yes, if image file name is specified in the proper property for picture, table or table cell, it is assigned as a default value of Location parameter in OnHTMLSaveImage.
But for the main background, file name is not stored. You must store it somewhere yourself.
This event stores the main background if (RVData=Sender.RVData) and (ItemNo<0).
remixtech
Posts: 49
Joined: Mon Jun 18, 2007 3:53 pm

Post by remixtech »

Okay ;) thanks,
Post Reply