【问题标题】:How to read pages in a Word document (C#)如何阅读 Word 文档中的页面 (C#)
【发布时间】:2012-07-27 11:22:16
【问题描述】:

我们使用 PDF-Focus。我们希望将横向格式的 PDF 文档导出为 Word 文档。 我们想将此文档导出到 Word。我们在 Word 中获取文档。一切看起来都很好。 如果我们想打印这个新的 word 文档,那么这个文档的边距是纵向的。

我试图通过创建一个空的 Word 文档然后插入一个临时导出的 Word 文档来解决这个问题。然后我将方向更改为横向。我看到这个解决方案有效。该文档现在是横向的。

但是现在带有图形和其他图像的页面与带有表格的页面重叠。

所以我想我必须通过读取单独的页面然后循环插入来将临时文档插入到新创建的文档中。

我们应该使用哪个功能以编程方式解决这个问题? 或者也许有更好的解决方案?你能帮帮我吗?

韦斯利

【问题讨论】:

    标签: c# ms-word interop


    【解决方案1】:

    以下代码适用于我并打开一个改变其页面方向的 Word 文档。你在找这样的东西吗?

    using System;
    using Microsoft.Office.Interop.Word;
    
    namespace PageSetup
    {
        class TestPageOrientation
        {
            static void Main(string[] args)
            {
                var app = new Microsoft.Office.Interop.Word.Application();
                app.Visible = true;
    
                //Load Document
                Document document = app.Documents.Open(@"C:\Temp\myDocument.docx");
    
                document.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
            }
        }
    }
    

    【讨论】:

    • **感谢您的回答。但是我已经尝试过这种方式。但这听起来很愚蠢。但是当我将方向更改为 wdOrientLandscape 时,文档会查看 Portrait???? **
    • 对不起!通过这种方式,我得到了面向纵向格式的文档。
    【解决方案2】:
    using System;
    using Microsoft.Office.Interop.Word;
    
    namespace PageSetup
    {
        class TestPageOrientation
        {
            static void Main(string[] args)
            {
                var app = new Microsoft.Office.Interop.Word.Application();
                app.Visible = true;
    
                //Load Document
                Document document = app.Documents.Open(@"C:\Temp\myDocument.docx");
    
                // I've added this rows below. ...And that works
                document.Sections.First.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
                document.Sections.Last.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
                document.PageSetup.Orientation = WdOrientation.wdOrientLandscape;
    
                // ... and this. But the LeftMargin I can leave it.
                document.PageSetup.LeftMargin = 1.00F;
                document.Save();
            }
        }
    }
    

    我不知道它在 Word 库源中是如何工作的。但是我已经尝试过 WdOrientation.wdOrientPortrait 并且有一次让我感到惊讶。我看到这个页面是横向格式的。

    我认为我的文档部分有问题,因为文档(包含大量表格、图形和图像)太大了。并且只有在使用了这种方法之后。

    所以我的下一个问题是:如何缩小这个 Word 文档的大小

    我该怎么做才能限制这个word文档中格式设置的数量

    【讨论】:

      【解决方案3】:

      问题在于 PDFFocus 将 PDF 转换为 RTF 格式。如果您更改设置,文档的大小会快速增长

      所以我解决了这个问题,首先将其保存为带有 RTF 扩展名的 RTF 文档。然后我将此文档保存为带有 DOC 扩展名 的 Word97 文档。

      我为这两个转换使用了相同的文档名称。两者都带有 DOC 扩展名。 另存为 Word97 文档不起作用。我认为这是 Word 2007 的错误。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-08-10
        • 2011-12-20
        • 2018-12-02
        • 1970-01-01
        • 2011-01-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多