c# - Word 2010 Interop PDF 导出缺少边框线

标签 c# interop ms-word word-2010

我有一个奇怪的问题...我正在使用 Word 2010 Interop,将 WordML 文档导出为 PDF。 有一个带顶线和底线的页脚:

<w:pBdr>
  <w:top w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="auto"/>
  <w:bottom w:val="single" w:sz="8" wx:bdrwidth="20" w:space="0" w:color="auto"/>
</w:pBdr>

打开文档后我使用

            doc.ExportAsFixedFormat(
                outputFileName.ToString(),
                exportFormat,
                openAfterExport,
                optimizeFor,
                range,
                0,
                0,
                item,
                includeDocProps,
                keepIRM,
                createBookmarks,
                docStructureTags,
                bitmapMissingFonts,
                useISO19005_1
                );

保存为PDF。它保存得很好,但页脚中没有显示顶部和底部的行。如果我使用 Word 2010 手动打开文档并使用另存为/发布,则会出现这些行。有什么想法吗?

最佳答案

事实证明这是一个非常微妙(且尚未确定)的类(Class)冲突问题。将转换器移至单独的类库后,它工作正常。

我在这里发布我的代码,以防有人感兴趣。

    public static void ConvertToPdf(string fileName, string outputFileName)
    {
        Application word = null;
        try
        {
            word = new Application();

            Object tempName = fileName;
            // Cast as Object for word Open method
            Object confirmConversions = false;
            Object readOnly = true;
            Object addToRecentFiles = false;
            Object visible = false;
            Object openAndRepair = true;
            Object format = WdOpenFormat.wdOpenFormatXML;
            object oMissing = Missing.Value;
            // Use the dummy value as a placeholder for optional arguments
            Document doc = word.Documents.Open(
                ref tempName,
                ref confirmConversions,
                ref readOnly,
                ref addToRecentFiles,
                ref oMissing, //PasswordDocument
                ref oMissing, //PasswordTemplate
                ref oMissing, //Revert
                ref oMissing, //WritePasswordDocument
                ref oMissing, //WritePasswordTemplate
                ref oMissing, //Format
                ref oMissing, //Encoding
                ref visible, //Visible
                ref openAndRepair, //OpenAndRepair
                ref oMissing, //DocumentDirection
                ref oMissing, //NoEncodingDialog
                ref oMissing //XmlTransform
                );
            doc.Activate();

            const WdExportFormat exportFormat = WdExportFormat.wdExportFormatPDF;
            const bool openAfterExport = false;
            const WdExportOptimizeFor optimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint;
            const WdExportRange range = WdExportRange.wdExportAllDocument;
            const WdExportItem item = WdExportItem.wdExportDocumentWithMarkup;
            const bool includeDocProps = false;
            const bool keepIrm = false;
            const WdExportCreateBookmarks createBookmarks = WdExportCreateBookmarks.wdExportCreateHeadingBookmarks;
            const bool docStructureTags = false;
            const bool bitmapMissingFonts = false;
            const bool useIso190051 = false;

            doc.ExportAsFixedFormat(
                outputFileName,
                exportFormat,
                openAfterExport,
                optimizeFor,
                range,
                0,
                0,
                item,
                includeDocProps,
                keepIrm,
                createBookmarks,
                docStructureTags,
                bitmapMissingFonts,
                useIso190051
                );


            // Close the Word document, but leave the Word application open.
            object saveChanges = WdSaveOptions.wdDoNotSaveChanges;
            ((_Document) doc).Close(ref saveChanges, ref oMissing, ref oMissing);
            doc = null;
        }
        catch (Exception ex)
        {
            Logger.Fatal(ex);
        }
        finally
        {
            if (word != null)
            {
                ((_Application) word).Quit();
                word = null;
            }
        }
    }

关于c# - Word 2010 Interop PDF 导出缺少边框线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13039884/

相关文章:

c# - 有没有办法在所有构造函数运行后立即自动调用特定方法?

.net - 如何编码(marshal)结构数组 - (.Net/C# => C++)

c# - 当使用 Microsoft.Office.Interop.Word 将 html 转换为 Word 时,字体大小不一样

python - 需要帮助使用 python 生成 PDF 或 Doc 格式的报告

c# - 在 href 中为标签调用两个 javascript 函数

c# - MVVM 中的上下文菜单

c# - 使用 T4 和 C# 在运行时编译动态代码

c# - 在 C#/WPF 应用程序中使用 ActiveX 控件(无关联的 UI)

c# - System.Runtime.InteropServices.ComTypes.IStream 到 System.IO.Stream

html - 在 html 中为 Chrome、Explorer 和 word 创建分页符