如何在不使用任何工具的情况下将Html转换为Rtf格式? [英] How do I convert Html to Rtf format without using any tool?

查看:142
本文介绍了如何在不使用任何工具的情况下将Html转换为Rtf格式?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发Windows项目,我想在Rich Text Box中显示html内容。

I am working on windows project, I want to display html content in Rich Text Box.

推荐答案

编写一个可以将HTML读入某种内部格式的转换器,然后编写第二个转换,将其写入RTF。请注意,很多HTML格式都很糟糕,这意味着您的读者必须非常灵活。



它们不相似:它们的工作方式不同。因此,您不能只是将<替换为{而将>替换为} - 您必须正确读取,处理它,然后从中间结果生成格式良好的RTF。 br $> b $ b

或者使用工具。 XHTML2RTF:基于XSL的HTML到RTF转换工具 [ ^ ]
Write a converter which can read HTML into some internal format, and then write a second convert which writes that to RTF. Be aware that a lot of HTML is badly formed, which means your reader will have to be pretty flexible.

They aren't similar: they do not work the same. So you can't just "replace the "<" with "{" and the ">" with "}" - you have to properly read it, process it, and then generate well formed RTF from the intermediate result.

Or use a tool. XHTML2RTF: An HTML to RTF conversion tool based on XSL[^]


不使用任何工具可能意味着你必须开发这样的工具。也许你想说没有任何第三方工具。



首先,你必须解析HTML。你可以这样做,因为HTML在W3标准中有完整的描述,但它也应该包括解析CSS并解释所有样式的最终渲染。请参阅:

W3C HTML [ ^ ],

层叠样式表 [ ^ ]。



然后你需要在RTF生产中撰写RTF文档并映射HTML元素。即使此格式是专有的,您也可以获得其完整描述:下载Word 2007:Rich Text格式(RTF)规范,版本1.9.1来自官方Microsoft下载中心 [ ^ ]。



我希望通过查看规格可以了解工作量是多少需要。



-SA
"Without using any tool" probably means that you have to develop such tool. Probably, you meant to say "without any 3rd-party tool".

First, you have to parse HTML. You can do it, because HTML is fully described in W3 standard, but it also should include parsing of CSS and interpreting final rendering of all styles. Please see:
W3C HTML[^],
Cascading Style Sheets[^].

Then you need to compose RTF document and map HTML element on you RTF production. Even though this format is proprietary, you can obtain its full description: Download Word 2007: Rich Text Format (RTF) Specification, version 1.9.1 from Official Microsoft Download Center[^].

I hope looking at the specs can give you an idea on how much work is required.

—SA


这篇关于如何在不使用任何工具的情况下将Html转换为Rtf格式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆