c# - 将 RichTextBox 中的彩色文本保存为 pdf
问题描述
我遇到了以下问题:
我在 WinForms 中有一个 RichTextBox,我在其中根据条件更改了几行的颜色。
我现在想将 RichTextBox 的内容保存在 PDF 中,使用iTextSharp
.
但是每当我打开保存的文件时,我只得到黑线,颜色丢失
我的代码:
string str = txt_result.Text;
string path = "";
SaveFileDialog dlg = new SaveFileDialog();
dlg.Filter = "pdf files (*.pdf)|*.pdf";
dlg.Title = "Als PDF speichern";
if (dlg.ShowDialog() == DialogResult.OK)
{
path = dlg.FileName;
}
Document document = new Document(PageSize.A4);
var output = new FileStream(path, FileMode.Create);
var writer = PdfWriter.GetInstance(document, output);
document.Open();
document.Add(new iTextSharp.text.Paragraph(str));
document.Close();
writer.Close();
output.Close();
谢谢您的帮助!
编辑:我已经尝试过txt_result.rtf
,但是使用 RTF 我只能在文件中得到神秘符号
解决方案
推荐阅读
- python - python中的线性回归严重错误,回归线完全错误
- php - 将中缀表达式转换为弹性搜索查询
- sql - SQL Server:如何按值分组,多列n天
- git - 从 BAT 文件运行 .exe 文件并等待执行,然后再运行下一组命令
- ios - 我添加到 iOS 应用程序的自定义字体是否可用于设备上的其他应用程序?
- osb - 如何按原样发送特殊字符数据:XQUERY 或 OSB 中的 MAU`A`
- html - 我想使用 DOM 但现在我有错误
- c# - Application.streamingAssetsPath 和 Application.persistentDataPath 有什么区别?它们是如何使用的?
- firebase - 将 Firebase 数据设置为 html 文件中的属性
- jupyter-notebook - 使用 jupyter notebook 时出现 ipykernel 错误