Skip to content

打开并显示简历

03xiaoyuhe edited this page Dec 5, 2024 · 3 revisions

即,该部分用于提供打开文件的渲染服务

详细设计

该部分以用户控件库的模式实现

简历显示控件FileRender

简历显示控件提供两种展示函数:

  • Show(sting )

    • 传入参数:
      • 文件路径string
  • Show(ResumeFile )

    • 传入参数:
      • 文件对象ResumeFile

关于打开Word文件

使用Aspose.Words库提取简历文件信息,并通过富文本显示控件RichTextBox,将word文件显示在自定义渲染控件中。

示例代码

using Aspose.Words;
using System.IO;
using System.Windows.Documents;

public void OpenWord(string fileName, RichTextBox richTextBox)
{
    try
    {
        // 加载 Word 文档
        Document doc = new Document(fileName);

        // 将文档保存为 XAML 流
        using (MemoryStream xamlStream = new MemoryStream())
        {
            doc.Save(xamlStream, SaveFormat.XamlFlow);
            xamlStream.Position = 0;

            // 将 XAML 流加载到 FlowDocument
            FlowDocument flowDocument = System.Windows.Markup.XamlReader.Load(xamlStream) as FlowDocument;

            // 设置到 RichTextBox
            richTextBox.Document = flowDocument;
        }
    }
    catch (IOException ioEx)
    {
        MessageBox.Show($"无法打开文件: {ioEx.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
    }
    catch (Exception ex)
    {
        MessageBox.Show($"发生错误: {ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
    }
}

打开并显示PDF

Clone this wiki locally