how can RichViewEdit document save as *.mht?

General TRichView support forum. Please post your questions here
Post Reply
yh01110
Posts: 9
Joined: Thu Apr 21, 2011 12:43 am

how can RichViewEdit document save as *.mht?

Post by yh01110 »

the *.mht file includes images¡£
gary
Posts: 163
Joined: Wed Aug 31, 2005 1:36 pm

Post by gary »

As far as I know, RichViewEdit can only save to html format.
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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 )
yh01110
Posts: 9
Joined: Thu Apr 21, 2011 12:43 am

Post 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;
Post Reply