将RTF转换为PDF格式 [英] Convert RTF to PDF format

查看:208
本文介绍了将RTF转换为PDF格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将RTF转换为文本格式以及保留样式和字体的任何想法?

Any ideas how to convert RTF to Text format and to keep both style and fonts?

注意:

我想避免使用 System.Windows.Forms

更新

我在RTF中有这样的东西

I have something like this in RTF

<P style="TEXT-ALIGN: center; MARGIN: 0in 0in 0pt" class=MsoNormal align=center><FONT
face=Calibri><SPAN style="LINE-HEIGHT: 115%; FONT-SIZE: 14pt"><STRONG>Questions and
Answers<BR style="mso-special-character: line-break"></STRONG><BR style="mso-specialcharacter:
line-break"></SPAN><SPAN style="LINE-HEIGHT: 115%; FONT-SIZE:
12pt"><?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office"
/><o:p></o:p></SPAN></FONT></P>
...
#558ED5; mso-style-textfill-fill-themecolor: text2; mso-style-textfill-fill-alpha: 100.0%; mso-style-textfillfill-
colortransforms: 'lumm=60000 lumo=40000'"><FONT color=#3366ff><SPAN style="LINEHEIGHT:
115%; FONT-SIZE: 14pt"><A title="Context Menu Default Items"
href="http://PG1/FocusOrthoServer/Images/Help/Helps/FocusOrthoHelp.aspx?HelpPageID=368"
target=_blank><FONT size=3 face="Times New Roman">Context Menu Default
Items</FONT></A></SPAN></FONT></SPAN></U><FONT
color=#000000>.<o:p></o:p></FONT></SPAN></P></FONT></FONT><o:p></o:p>

实际上显示帮助文本。我需要将该文本写成PDF格式!

Which actually displays a help text. I need to write that text to a PDF as it is!

PS

我正在使用iTextSharp

I am using iTextSharp

推荐答案

编辑

根据您的编辑,答案要简单得多。只需解析文件并将各个元素与其格式标签一起存储。

Based on your edit the answer is a lot simpler. Just parse the file and store the individual elements together with their formatting tags.

然后创建一个pdf文档并写出应用与o匹配的样式的文本元素严格的格式标签。实施起来很耗时,但它会起作用。

Then create a pdf document and write out the text elements applying styles that match the original formatting tags. It's time consuming to implement but it will work.

几年前我做过类似的事情。

I've done something similar a few years ago.

或者,您可以使用PDFSharp的虚拟打印机(或任何其他pdf虚拟打印机)来轻松实现这一目标。只需打印到PDF:)

Alternatively you could use PDFSharp's virtual printer (or any other pdf virtual printer for that matter) to do this hassle free. Just print to PDF :)

原帖:

你不能拥有纯文本格式(我可以从你的问题中假设)可以进行文本格式化。

You cannot have a plain text format (that's what I can assume from your question) that would have text formatting.

标签就像RTF这样的格式首先保持格式化。因此,删除所有标签会为您提供纯文本文档。

Tags is how formats like RTF maintain formatting in the first place. So getting rid of all tags gives you a plain text document.

但是,您可以使用某种元文件来存储有关纯文本文档的格式数据。

However, you could have some sort of a meta file that would store the formatting data about your plain text document.

这个想法很简单,您可以使用单词位置(行号和列号)作为格式化标签的键,这些标签将以xml或您想要的任何其他文件格式存储。您最终会得到两个文件plain.txt和plain.meta。

The idea is simple, you use word positions (line and column numbers) as keys to formatting tags that you will store in an xml or any other file format you want. You will end up with two files plain.txt and plain.meta.

希望这会有所帮助。

这篇关于将RTF转换为PDF格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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