How To convert Unicode RTF string(International) to HTML
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: How To convert Unicode RTF string(International) to HTML

Hybrid View

  1. #1
    Join Date
    Feb 2005
    Posts
    64

    How To convert Unicode RTF string(International) to HTML

    Hi,
    I am converting an application in to unicode.
    my input string is an RTF string, and I need to convert this in to corresponding HTML string.

    here is the input string:
    This is for chineese language..

    "{\rtf1\ansi\ansicpg1252\deff0\deflang1033{\fonttbl{\f0\fmodern\fprq6\fcharset134 SimSun;}}
    {\colortbl ;\red0\green0\blue"}\viewkind4\uc1\pard\cf1\lang2052\f0\fs20\'cc\'d8\par
    }"}

    In this string between \fs20 and \par is the MESSAGE, which is in chineese.

    now in my parser I need to convert the equavalant message of this message in to HTML..

    So, How can I achieve this...

    Regs

  2. #2
    Join Date
    Jun 2005
    Location
    Tirunelveli-Tamil Nadu-India
    Posts
    354

    Smile Re: How To convert Unicode RTF string(International) to HTML

    If I Helped You, "Rate This Post"

    Thanks
    Guna

  3. #3
    Join Date
    Feb 2005
    Posts
    64

    Re: How To convert Unicode RTF string(International) to HTML

    Hi,
    I check this link, but could not find much useful. Can u suggest something else...

  4. #4
    Join Date
    Sep 2012
    Posts
    4

    Thumbs up Re: How To convert Unicode RTF string(International) to HTML

    Disclaimer: I'm working for this company.
    Hi. You can try to use "RTF to HTML DLL .Net" for this. Library supports rtf to html converting and doesn't require installed ms office or any other word-processor. Full version for the 1 Developer and 1 Server License costs $239(US) now. Or you can try to use the trial version. The trial version is complete functional and differs from full only that:

    1/Converts only first 30,000 symbols
    2/Can be used only for evaluating and testing

    Sample code for the rtf to html converting in C++:

    RTF-to-HTML DLL Win32 - имя бесплатной библиотеки

    Code:
    #include <windows.h>
    #include <stdlib.h>
    #include <stdio.h>
    
    struct convertOptions
    {
    	int  htmlType;			 //0-XHTML, 1- HTML, 2-HTML+CSS
    	char title[120];		 //Page title	
    	char extension[10];		 //for example, ".html"
    	char fontFace[50];		 //for example, "Arial" or "Times New Roman"
    	char fontSize[10];		 //for example ,"10"
    	int  preserveImages;	 //0-no, 1 - yes 
    	int  preserveFontFace;	 //0-no, 1 - yes 
    	int  preserveFontSize;	 //0-no, 1 - yes 
    	int  preserveFontColor;	 //0-no, 1 - yes 
    	int  preserveHyperlinks;	//0-no, 1 - yes
    	int  tableBorders;		 //0-invisble, 1 - visible
    	int  encoding;			 /* Windows_1250=0, Windows_1251=1, Windows_1252=2, Windows_1253=3,
    								Windows_1254=4, Windows_1255=5, Windows_1256=6, Windows_1257=7,
    								Windows_1258=8, ISO_8859_1=9,	ISO_8859_2=10,	ISO_8859_3=11,
    								ISO_8859_4=12,	ISO_8859_5=13,	ISO_8859_6=14,	ISO_8859_7=15,
    								ISO_8859_8=16,	ISO_8859_9=17,	KOI8_R=18,		UTF_8=19	*/
    	int  htmlParts;			 //0-html Complete, 1 - only between <body>..</body>
    	char imageFolder[500];	 //folder where image will be stored
    	char cssStyleName[120];	 //style name, for example "ts"
    	int  fontSizesType;		 //0-normal sizes, 1 - medium sizes, 2 - big sizes, 3 - huge sizes
    	char imageSubfolder[120];//will create subfolder for storing images, if ""-empty string then images will be strored in 'image_folder' 
    	int  hyperlinkTarget;	 //0 - no target, 1 - target="_blank",  2 - _self, 3 - _parent, 4 - _top
    	int  cssStartNumber;	 //number for style name, like a .tsN (.ts1 or .ts100)
    	char Serial[12];
    };
    
    
    
    typedef int (* cfunc)(char * rtffile, char *outfolder, struct convertOptions);
    cfunc ConvertFile;
    
    
    int main() 
    {	
    
    	int ret;
    	char rtffile[_MAX_PATH];
    	char outfolder[_MAX_PATH];
    
    	//load library
    	HINSTANCE hMod=LoadLibrary("Sautinsoft.RTFToHTML.Win32.dll");
    
    	if(hMod==NULL) 
    	{
    	  printf("Unable to load library\n");
    	  getchar();
    	  return 0;
    	}
    	ConvertFile=(cfunc)GetProcAddress(hMod,"ConvertFile");
    	if (ConvertFile==NULL)
    	{
    		printf("Can't load function.\n");
    		FreeLibrary((HMODULE)hMod);
    		getchar();
    		return 0;
    	}
    	//
    	printf("Please enter rtf file (example: d:\\my.rtf):\n");
    	gets(rtffile);
    	printf("Please enter output folder (example : d:\\temp):\n");
    	gets(outfolder);
    
    	//set conversion params
    	struct convertOptions ct;
    	ct.cssStartNumber=1;
    	strcpy(ct.cssStyleName,"ts");
    	ct.encoding=9;
    	strcpy(ct.extension,".htm");
    	strcpy(ct.fontFace,"Verdana");
    	strcpy(ct.fontSize,"10");
    	ct.htmlType=1;
    	ct.preserveFontColor=1;
    	ct.preserveFontFace=1;
    	ct.preserveFontSize=1;
    	ct.preserveImages=1;
    	ct.preserveHyperlinks=1;
    	ct.tableBorders=1;
    	ct.htmlParts=0; //only between <body>...</body>	
    	strcpy(ct.title,"My Page");
    	strcpy(ct.imageFolder,"D:\\");
    	strcpy(ct.imageSubfolder,"test.files");
    	ct.hyperlinkTarget=0;
    	strcpy(ct.Serial,"Serial number");
    
    	
    	ret=ConvertFile(rtffile,outfolder,ct);
    
    	switch(ret)
    	{		
    		case -1 : puts("Check your serial number");break;
    		case 0 : puts("Conversion completed");break;
    		case 2 : puts("Not enough memory"); break;
    		case 3 : puts("Can't open output file"); break;
    		case 4 : puts("Can't open input file"); break;
    		case 5 : puts("The input file has zerow length"); break;
    		default: break;
    	}
    	//flushall
    	getchar();
    	FreeLibrary((HMODULE)hMod);
    	return 0;
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center