Page 1 of 1

how can RichViewEdit document save as *.mht?

Posted: Thu Jun 09, 2011 7:06 am
by yh01110
the *.mht file includes images¡£

Posted: Thu Jun 09, 2011 8:25 am
by gary
As far as I know, RichViewEdit can only save to html format.

Posted: Thu Jun 09, 2011 6:21 pm
by Sergey Tkachenko
See http://www.trichview.com/forums/viewtopic.php?t=11
The code for saving MHT files does not require any additional components (except for units for base64 encoding, included).
The same zip file includes examples for sending HTML emails using Indy (some corrections may be required depending on Indy version, they change programming interface often)

(another related resource - working with HTML emails using CleverComponents - http://www.trichview.com/forums/viewtopic.php?t=4123 )

Posted: Fri Jun 10, 2011 12:54 am
by yh01110
thank u !
here is my code

Code: Select all

var
  itype:integer;
  str :string;
  Stream: TMemoryStream;
  Path, Title, ImagesPrefix, ExtraStyles, ExternalCSS, CPPrefix: String;
  Options: TRVSaveOptions ;
  bltype:integer;
  s2:string;
    s: TRVRawByteString;
    boundary: TRVRawByteString;
    i: Integer;
    slist:Tstringlist;
    ss:string;
begin
   slist:=Tstringlist.create;
  HTMLImages := THTMLImagesCollection.Create;
   // saving HTML
  Stream := TMemoryStream.Create;
  SRichViewEdit1.RichViewEdit.SaveHTMLToStreamEx(Stream, '', 'Web Archive Demo', '', '', '', '',
    [rvsoUseCheckpointsNames, rvsoUTF8]);
      Stream.Position :=0;
  SetLength(s, Stream.Size);
  Stream.ReadBuffer(PRVAnsiChar(s)^, Length(s));

  s := MimeEncodeString(s);
 // showmessage(s);
 // Stream.Free;

  // now s contains HTML file without images, base64-encoded. saving it in MIME
  boundary := '----=_BOUNDARY_LINE_';
  //AssignFile(F, SaveDialog1.FileName);
  //Rewrite(F);
  slist.add('From: <Saved by TRICHVIEW.COM Demo>');
  slist.add('Subject: MIME Test');
  slist.add('MIME-Version: 1.0');
  slist.add('Content-Type: multipart/alternative;');
  slist.add(#9+'boundary="'+boundary+'"');
  slist.add('X-Unsent: 1');
  slist.add('');;
  slist.add('This is a multi-part message in MIME format.');
  slist.add('');
  slist.add('--'+ boundary);
  slist.add('Content-Type: text/html;');
  slist.add(#9+'charset="utf-8"');
  slist.add('Content-Transfer-Encoding: base64');
  slist.add('');
  slist.add(s);
  // saving images
  for i := 0 to HTMLImages.Count-1 do begin
  slist.add('');
   slist.add('--'+boundary);
    SetLength(s, HTMLImages[i].Stream.Size);
    HTMLImages[i].Stream.Position := 0;
    HTMLImages[i].Stream.ReadBuffer(PRVAnsiChar(s)^, Length(s));
    s := MimeEncodeString(s);
    slist.add('Content-Type: '+ HTMLImages[i].ContentType);
    slist.add(#9'Name="'+ HTMLImages[i].Name+ '"');
    slist.add('Content-Transfer-Encoding: base64');
    slist.add('Content-ID: <'+ HTMLImages[i].Name+ '>');
  slist.add('');
    slist.add(s);
  end;
  slist.add('');
  slist.add('--'+ boundary+ '--');

  Memo1.Clear ;
  Memo1.Lines.AddStrings(slist); 
end;