C# 在不使用office的情况下获取docx文件的高度和宽度

C# 在不使用office的情况下获取docx文件的高度和宽度,c#,ms-word,C#,Ms Word,我在下一个代码中获得页面数: using DocumentFormat.OpenXml.Packaging; WordprocessingDocument doc = WordprocessingDocument.Open( @"D:\2pages.docx", false ); Console.WriteLine( doc.ExtendedFilePropertiesPart.Properties.Pages.InnerText.ToString() ); 我能用这种方法得到文件

我在下一个代码中获得页面数:

using DocumentFormat.OpenXml.Packaging;

WordprocessingDocument doc = WordprocessingDocument.Open( @"D:\2pages.docx", false );

Console.WriteLine(
    doc.ExtendedFilePropertiesPart.Properties.Pages.InnerText.ToString()
);
我能用这种方法得到文件的高度和宽度吗? 或者以另一种方式,但不使用office。

Aspose.Word(不是免费的)内置了以下功能:

有人遇到了类似的问题,下面是关于SO的讨论(但使用OpenXML):


也许您可以从中扣除答案。

请使用PageSetup.PageHeight和PageSetup.PageWidth属性获取页面的高度和宽度。希望这对你有帮助

Document doc = new Document(MyDir + "input.docx");

Console.WriteLine(doc.FirstSection.PageSetup.PageHeight);
Console.WriteLine(doc.FirstSection.PageSetup.PageWidth);

我与Aspose合作,担任开发人员福音传道者。

什么是“文件的高度和宽度”?页面的尺寸?请注意,通常情况下,一个Word文档可能包含多个具有不同页面维度的部分。为了与document和MyDir Word一起使用,我需要使用dll/using/reference。因为我尝试过,但我的程序不知道这些单词。非常感谢您的尝试!正在等待您的答案Rachell参考DLL是,MyDir是字符串变量。您有没有其他答案而不使用with not free DLL?您有没有其他答案而不使用with not free DLL?谢谢你的款待!
Document doc = new Document(MyDir + "input.docx");

Console.WriteLine(doc.FirstSection.PageSetup.PageHeight);
Console.WriteLine(doc.FirstSection.PageSetup.PageWidth);