如何阅读Word文档(C#)中的页面

问题描述:

我们使用PDF-Focus.我们希望将横向格式的PDF文档导出为Word文档. 我们希望将此文档导出到Word.我们用Word获取文档.一切看起来都很好. 如果要打印此新的Word文档,则此文档的边距应为纵向.

We use PDF-Focus. And we want to export PDF-documents in landscape-format to a Word-document. We want to export this document to Word. We get the document in Word. And everything looks fine. If we want to print this new word-document the margins of this document are portrait-orientated.

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

I tried to solve this by creating an empty Word document and then inserting a temporary exported Word-document. Then I changed the orientation to Landscape. I saw that this solution works. The document is now landscape orientated.

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

But now the pages with graphics and other images are overlapping the pages with tables.

所以我认为我必须通过阅读单独的页面然后将其插入到循环中来将临时文档插入到新创建的文档中.

So I thought I have to inserting the temporary document to the new created document by reading separate pages and then inserting with a loop.

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

Which functionality should we use to solve this programmatically? Or maybe there is a better solution? Can you help me?

卫斯理

以下代码对我有用,并打开一个更改其页面方向的Word文档.您在寻找这样的东西吗?

Following code works for me and opens a word document changing its page orientation. were you looking for something like this?

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