Word 2010的互操作PDF导出缺少的边界线 [英] Word 2010 Interop PDF Export missing border line

查看:649
本文介绍了Word 2010的互操作PDF导出缺少的边界线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题...我使用Word 2010 Interop,导出一个WordML文档到PDF。
有一个顶部和底部的页脚:

I have a strange issue ... I am using Word 2010 Interop, exporting a WordML document to PDF. There is a footer with top and bottom lines:

<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手动打开文档,并使用SaveAs / Publish,则存在行。任何想法?

to save as PDF. It saves fine, but the top and bottom lines do not show up in the footer. If I open the document manually with Word 2010 and use SaveAs/Publish, the lines are present. Any ideas?

推荐答案

结果是一个非常微妙的(但尚待识别)类冲突问题。将转换器移动到单独的类库后,它工作正常。

It turned out to be a very subtle (and yet to be identified) class conflict issue. After moving the converter to a separate class library, it is working fine.

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

I am posting my code here, in case someone is interested.

    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;
            }
        }
    }

这篇关于Word 2010的互操作PDF导出缺少的边界线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆