c# - 使用 c# 和 Interop 另存为 PDF 不将嵌入的 pdf 保存在 word 文档中

标签 c# pdf ms-word office-interop

背景:我正在尝试使用 c# 和 Interop 生成一个 word 文档。我成功地插入了表格、页眉、页脚、图表……大部分都工作正常。下一步,我希望将其转换为 pdf。

流程调整:由于我使用的是 word 2011 和 word 2007(在安装 saveaspdf 插件之后),我使用“另存为”将文档保存为 pdf,然后将文件类型设置为 pdf。

出现的问题:我已经使用以下代码成功地将 pdf 嵌入到我的文档中。

        Object oIconLabel = new FileInfo(file_path).Name;
        Object oFileDesignInfo = file_path;
        Object oClassType = "AcroExch.Document.7";
        Object oTrue = true;
        Object oFalse = false;
        Object oMissing = System.Reflection.Missing.Value;
        Object index = 0;
        Range r = d.Bookmarks.get_Item(ref eod).Range;

        r.InlineShapes.AddOLEObject(
            ref oClassType, ref oFileDesignInfo, ref oFalse, ref oTrue, ref oMissing,
            ref index, ref oIconLabel, ref oMissing);

这里的 d 是 Document 对象。现在,当我尝试将此 word 文档保存为 pdf 时,使用

 d.SaveAs(ref filename, ref filetype, ref oMissing, ref oMissing, ref oMissing, 
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, 
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing);

pdf 正在生成。但是我嵌入的文档没有嵌入到生成的 pdf 中。而是只显示一个图标。

如何将文档嵌入到 pdf 中?我们通常如何处理这种情况。如果问题不清楚,请告诉我。

最佳答案

是我选错了api。它不应该另存为。它是 ExportAsFixedFormat。

文档存在here

示例用法可以是

d.ExportAsFixedFormat(filename.ToString(), WdExportFormat.wdExportFormatPDF,false,WdExportOptimizeFor.wdExportOptimizeForOnScreen,
                    WdExportRange.wdExportAllDocument,1,1,WdExportItem.wdExportDocumentContent,true,true,
                    WdExportCreateBookmarks.wdExportCreateHeadingBookmarks,true,true,false,ref oMissing);

关于c# - 使用 c# 和 Interop 另存为 PDF 不将嵌入的 pdf 保存在 word 文档中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11770821/

相关文章:

c# - 如何连接用不同语言编写的客户端服务器

java - RegEx : Where should I start? 之后分割 PDF

vba - 使用 VBA 宏选择和复制 Outlook 电子邮件正文

vba - 从 Excel 调用 Word VBA MsgBox 函数

wpf - 在没有打开对话框的情况下使用 WPF 打开 Word 文档

c# - EF 6 使用 TPT 报错都具有相同的主键值

C# 在不调用 ValueChanged 事件的情况下设置 UserControl.Value

时间:2019-03-08 标签:c#windowsformTabOrder

java - 大纲的新标题未保存

ios - 使用MuPDF从PDF提取文本时,文本的最后一行被截断