trichview.com

trichview.support




converting rtf to html


Return to index


Author

Message

Michael Schwarzl

Posted: 06/22/2002 18:47:28


I'm converting RTF text with a helper function. To export URLs too I

implemented a helper class which contains the two call back functions

(declared like help told me to):



type

  TrvConvertHelper = class

    FControl: TCustomRichView;

    FLinks: TStringList;

  private

    procedure URLNeeded(Sender: TCustomRichView; id: Integer; var url:

String);

    procedure ReadHyperlink(Sender: TCustomRichView; const Target, Extras:

String; DocFormat: TRVLoadFormat; var StyleNo, ItemTag: Integer; var

ItemName: String);

  end;



procedure TrvConvertHelper.ReadHyperlink(Sender: TCustomRichView;

  const Target, Extras: String; DocFormat: TRVLoadFormat; var StyleNo,

  ItemTag: Integer; var ItemName: String);

begin

  ItemTag := Integer(StrNew(PChar(Target)));

end;


procedure TrvConvertHelper.URLNeeded(Sender: TCustomRichView; id: Integer;

var url: String);

var

  RVData: TCustomRVFormattedData;

  ItemNo: Integer;

begin

  FControl.GetJumpPointLocation(id, RVData, ItemNo);

  url := PChar(RVData.GetItemTag(ItemNo));

end;



The helper routine:


function rvRTFToHTML(ARTF, ATempPath: String): String;

var

  ch: TrvConvertHelper;

  mem: TStringStream;

  rv: TRichView;

  rs: TRVStyle;

begin

  Result := '';

  mem := TStringStream.Create(ARTF);

  try

    rv := TRichView.Create(nil);

    rs := TRVStyle.Create(nil);

    ch := TrvConvertHelper.Create;

    try

      ch.FControl := rv;

      rv.Style := rs;

      rv.Options :=

[rvoAllowSelection,rvoScrollToEnd,rvoShowPageBreaks,rvoTagsArePChars,rvoAuto

CopyText,rvoAutoCopyUnicodeText,rvoAutoCopyRVF,rvoAutoCopyImage,rvoAutoCopyR

TF,rvoFormatInvalidate,rvoDblClickSelectsWord];

      rv.RTFOptions :=

[rvrtfDuplicateUnicode,rvrtfSaveEMFAsWMF,rvrtfSaveJpegAsJpeg];

      rv.RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;

      rv.RTFReadProperties.TextStyleMode := rvrsAddIfNeeded;

      rv.RTFReadProperties.UseHypertextStyles := True;

      rv.OnURLNeeded := ch.URLNeeded;

      rv.OnReadHyperlink := ch.ReadHyperlink;


      LoadXXXFromStream(mem, rv);

      mem.Size := 0;

      rv.SaveHTMLToStream(mem, ATempPath, '', 'img', [rvsoOverrideImages,

rvsoNoHypertextImageBorders, rvsoImageSizes, rvsoForceNonTextCSS,

rvsoUseCheckpointsNames]);

      Result := mem.DataString;

    finally

      rs.Free;

      rv.Free;

    end;

  finally

    mem.Free;

  end;

end;



But in URLNeeded

  FControl.GetJumpPointLocation(id, RVData, ItemNo);

results in an empty RVData (nil) is returned and url fetch fails.


What can I do to internally convert rtf to html - with urls?



begin 666 sample.rtf

M>UQR=&8Q7&%N<VE<86YS:6-P9S!<=6,Q7&1E9F8P7&1E9FQA;F<Q,#(T7&1E

M9FQA;F=F93$P,C1[7&9O;G1T8FQ[7&8P7&9N:6Q<9F-H87)S970Q($=A<F%M

M;VYD.WU[7&8Q7&9N:6Q<9F-H87)S970Q(%9E<F1A;F$[?7M<9C)<9FYI;%QF

M8VAA<G-E=#$@5&%H;VUA.WU]>UQC;VQO<G1B;#M<<F5D,%QG<F5E;C!<8FQU

M93 [7')E9#!<9W)E96XP7&)L=64R-34[7')E9#!<9W)E96XR-35<8FQU93(U

M-3M<<F5D,%QG<F5E;C(U-5QB;'5E,#M<<F5D,C4U7&=R965N,%QB;'5E,C4U

M.UQR960R-35<9W)E96XP7&)L=64P.UQR960R-35<9W)E96XR-35<8FQU93 [

M7')E9#(U-5QG<F5E;C(U-5QB;'5E,C4U.UQR960P7&=R965N,%QB;'5E,3(X

M.UQR960P7&=R965N,3(X7&)L=64Q,C@[7')E9#!<9W)E96XQ,CA<8FQU93 [

M7')E9#$R.%QG<F5E;C!<8FQU93$R.#M<<F5D,3(X7&=R965N,%QB;'5E,#M<

M<F5D,3(X7&=R965N,3(X7&)L=64P.UQR960Q,CA<9W)E96XQ,CA<8FQU93$R

M.#M<<F5D,3DR7&=R965N,3DR7&)L=64Q.3([?0T*7'5C,0T*7'!A<F1<<6Q<

M9FDP7&QI,%QR:3!<<V(P7'-A,%QI=&%P,"!<<&QA:6X@7&8P7&9S,C(@<VEM

M<&QE('M<9FEE;&1[7"I<9FQD:6YS="!(65!%4DQ)3DL@(G=W=RYU<FPN8V]M

H(GU[7&9L9')S;'1<<&QA:6X@7&8P7'5L7&9S,C)<8V8R(%523'U]?0``

`

end





Powered by ABC Amber Outlook Express Converter