iText - 如何在现有 RTF 文档上进行搜索/替换
目前我正在开发一个简单的邮件合并模块。
我需要加载纯 *.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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不认为 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
最后我决定使用 *.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.
您可以使用 RichTextBox 控件来查找/替换占位符。
之后,您可以使用以下命令获取 rtf 格式的文本:
You can use RichTextBox control to find/replace placeholders.
After this you can get rtf formatted text with: