iText - 如何在现有 RTF 文档上进行搜索/替换

发布于 2024-07-12 11:24:57 字数 246 浏览 9 评论 0原文

目前我正在开发一个简单的邮件合并模块。

我需要加载纯 *.RTF 模板,然后替换 [[field]] 标签中包含的所有单词并在末尾打印出来。

我发现 iText 库是免费的,能够加载/保存 pdf 和 rtf。 我设法加载 rtf,将几个副本合并到一个巨大的文档中,但我不知道如何用客户名称/地址等自定义数据替换 [[field]]。

该功能是否存在,如果存在 - 如何实现? 解决方案平台是c#/.NET

Currently I'm working on a simple Mail-Merge module.

I need to load plain *.RTF template, then replace all words enclosed in [[field]] tags and at the end and print them out.

I found the iText library which is free and capable of loading/saving pdfs and rtf.
I managed to load rtf, merge a few copies to one huge doc but I have no idea how to replace [[field]] by custom data like customer name/address.

Is that feature present, and if yes - how to do it?
The solution platform is c#/.NET

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

从此见与不见 2024-07-19 11:24:57

我不认为 pdf 是你想要的方式。

根据这篇文章,这充其量是极其困难的,而且是不可能的最糟糕的。

RTFLib 这样的东西对你来说会更好吗?

G-曼

I don't think that pdf is the way you want to go.

According to this article it is extremely difficult at best and not possible at worst.

Would something like RTFLib work better for you?

G-Man

浅听莫相离 2024-07-19 11:24:57

最后我决定使用 *.docx 和“Open XML SDK 2.0 for Microsoft Office”.NET 强类型包装器。

Finally I decided to use *.docx and "Open XML SDK 2.0 for Microsoft Office" .NET strongly typed wrapper.

空名 2024-07-19 11:24:57

您可以使用 RichTextBox 控件来查找/替换占位符。

RichTextBox rtb = new RichTextBox(); 
rtb.LoadFile("template.rtf");
string placeHolder = "[[placeholder_name]]"; 
int pos = rtb.Find(placeHolder); 
rtb.Select(pos, placeHolder.Length);
rtb.SelectedText = "new value";

之后,您可以使用以下命令获取 rtf 格式的文本:

rtb.Rtf;

You can use RichTextBox control to find/replace placeholders.

RichTextBox rtb = new RichTextBox(); 
rtb.LoadFile("template.rtf");
string placeHolder = "[[placeholder_name]]"; 
int pos = rtb.Find(placeHolder); 
rtb.Select(pos, placeHolder.Length);
rtb.SelectedText = "new value";

After this you can get rtf formatted text with:

rtb.Rtf;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文