how can RichViewEdit document save as *.mht?
Posted: Thu Jun 09, 2011 7:06 am
the *.mht file includes images¡£
Support forums for TRichView, ScaleRichView, Report Workshop and RVMedia components
https://richedit.com/forums/
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;