Página 1 de 1

RTF 2 HTML

Publicado: Jue Abr 28, 2016 11:56 am
por bingen
Buenas XTeam. Necesito pasar de RTF a HTML pero para esto hay que tener instalado Office y sus librerías de conversión.

Quisiera hacerlo directamente por que el cliente puede no tener siquiera el Office y para eso habría que fabricar un parser, o alguien lo tiene ya hecho, por favor.

He visto funciones en C para ello e intento implementarlas en Xailer pero con nulo resultado

//------------------------------------------------------------------------------
#pragma BEGINDUMP

#include <windows.h>
#include <xailer.h>

//--------------------------------------------------------------------------

XA_FUNC( XRTFTOHTML )

private static string ConvertRtfToXaml(string rtfText)

{

var richTextBox = new RichTextBox();

if (string.IsNullOrEmpty(rtfText)) return ““;

var textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

using (var rtfMemoryStream = new MemoryStream())

{

using (var rtfStreamWriter = new StreamWriter(rtfMemoryStream))

{

rtfStreamWriter.Write(rtfText);

rtfStreamWriter.Flush();

rtfMemoryStream.Seek(0, SeekOrigin.Begin);

textRange.Load(rtfMemoryStream, DataFormats.Rtf);

}

}

using (var rtfMemoryStream = new MemoryStream())

{

textRange = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd);

textRange.Save(rtfMemoryStream, DataFormats.Xaml);

rtfMemoryStream.Seek(0, SeekOrigin.Begin);

using (var rtfStreamReader = new StreamReader(rtfMemoryStream))

{

return rtfStreamReader.ReadToEnd();

}

}

}

//--------------------------------------------------------------------------

#pragma ENDDUMP

Re: RTF 2 HTML (Solucionado)

Publicado: Lun May 09, 2016 1:20 pm
por bingen
Buenas xTeam.

Ya he conseguido una manera de converir de RTF a HTML con unas DLL gratuitas (2 DLL = 200Kb) con manual, ejemplos, etc. muy bueno.

IRun RTF Converter version 1.18 Pilot Software Ltd.

http://www.pilotltd.com

Y la forma de ejecutarlo desde Xailer:

#pragma BEGINDUMP
#include "Windows.h"
#include "Xailer.h"

typedef int __stdcall (* EXRTF2WEB)
(const char* source,
const char* dest,
int options,
const char* title,
const char* bgcolor,
int dpi);

HB_FUNC( RTF2HTML ) // --> Rtf2Html( cFileRTF, cHTML, nOptions, cBackColor, cTitle, nDPI ) -> nResult OJO nDPI es obligatorio y como mínimo 30 Ejemplo Rtf2Html( "RtfFile.Rtf", "HtmlFile.Html", 7, , , 96 )
{
HINSTANCE inst;
EXRTF2WEB proc;
int ret = 0;

inst=LoadLibrary( (LPCTSTR)"irun.dll");
if(inst)
{
proc=(EXRTF2WEB)GetProcAddress(inst,(LPCTSTR)"EXRTF2WEB");
if(proc)
ret=(*proc)( hb_parc( 1 ), hb_parc( 2 ), hb_parnl( 3 ), hb_parc( 4 ), hb_parc( 5 ), hb_parnl( 6 ) );
FreeLibrary(inst);
}
hb_retnl( ret );
}

Re: RTF 2 HTML

Publicado: Lun May 09, 2016 5:30 pm
por avitalini
Excelente aportación Bingen, muchas gracias!

Re: RTF 2 HTML

Publicado: Lun May 09, 2016 5:55 pm
por ignacio
Hola Bingen,

Te animo a que lo subas al área de descargas.

Un saludo

Re: RTF 2 HTML

Publicado: Sab May 14, 2016 9:06 am
por bingen
Lo preparo y lo subo encantado, me faltaba probarlo un poco más.

Re: RTF 2 HTML

Publicado: Mar May 17, 2016 12:55 pm
por bingen
Ya lo subi el sábado pero no aparece ?¿??¿

Re: RTF 2 HTML

Publicado: Mar May 17, 2016 2:18 pm
por ignacio
subido. Muchas gracias