RTF to HTML conversion
Posted: Fri Oct 25, 2013 3:34 pm
I am having problems converting HTML to RTF. I uploaded the problematic files (original HTML and the resulting RTF) to http://www.dimastr.com/temp/conversion_problem.zip.
The relevant snippet of code is below
RvHtmlImporter := TRvHtmlImporter2.Create(Msg);
RVReportHelper := TRVReportHelper.Create(nil);
canvas:= TCanvas.Create;
RVStyle:= TRVStyle.Create(nil);
try
canvas.Handle := GetWindowDC (GetDesktopWindow);
RVReportHelper.RichView.Style := RVStyle;
RVReportHelper.RichView.OnReadHyperlink := RvHtmlImporter.OnReadHyperlink;
RVReportHelper.RichView.OnWriteHyperlink := RvHtmlImporter.OnWriteHyperlink;
RVReportHelper.Init(canvas, Screen.Width);
//RvHtmlImporter.RichView := TempRichView;
RvHtmlImporter.RichView := RVReportHelper.RichView;
RvHtmlImporter.ClearDocument := false;
RvHtmlImporter.BasePath := '';
RvHtmlImporter.LoadHtml(Value);
Stream := TMemoryStream.Create;
try
RVReportHelper.RichView.SaveRTFToStream(Stream, false);
if Stream.Size > 0 then begin
Stream.Position := 0;
SetLength(Result, Stream.Size);
Stream.Read(Result[1], Length(Result));
end;
bRtfConverted := true;
finally
Stream.Free;
end;
finally
RvHtmlImporter.Free;
RVStyle.Free;
RVReportHelper.Free;
canvas.Free;
end;
The relevant snippet of code is below
RvHtmlImporter := TRvHtmlImporter2.Create(Msg);
RVReportHelper := TRVReportHelper.Create(nil);
canvas:= TCanvas.Create;
RVStyle:= TRVStyle.Create(nil);
try
canvas.Handle := GetWindowDC (GetDesktopWindow);
RVReportHelper.RichView.Style := RVStyle;
RVReportHelper.RichView.OnReadHyperlink := RvHtmlImporter.OnReadHyperlink;
RVReportHelper.RichView.OnWriteHyperlink := RvHtmlImporter.OnWriteHyperlink;
RVReportHelper.Init(canvas, Screen.Width);
//RvHtmlImporter.RichView := TempRichView;
RvHtmlImporter.RichView := RVReportHelper.RichView;
RvHtmlImporter.ClearDocument := false;
RvHtmlImporter.BasePath := '';
RvHtmlImporter.LoadHtml(Value);
Stream := TMemoryStream.Create;
try
RVReportHelper.RichView.SaveRTFToStream(Stream, false);
if Stream.Size > 0 then begin
Stream.Position := 0;
SetLength(Result, Stream.Size);
Stream.Read(Result[1], Length(Result));
end;
bRtfConverted := true;
finally
Stream.Free;
end;
finally
RvHtmlImporter.Free;
RVStyle.Free;
RVReportHelper.Free;
canvas.Free;
end;