测量单位之间的转换
Contents
[
Hide
]
Aspose.Words API 中提供的大多数表示某种测量值的对象属性(例如宽度或高度、边距和各种距离)都接受以点为单位的值,其中 1 英寸等于 72 点。有时这并不方便,需要将点转换为其他单位。
Aspose.Words 提供了 ConvertUtil 类,该类提供了在各种测量单位之间进行转换的辅助函数。它可以转换:
- 英寸、像素和毫米转换为点
- 指向英寸和像素
- 从一种分辨率到另一种分辨率的像素
可以在 96 dpi(每英寸点数)分辨率或指定 dpi 分辨率下执行像素与点之间的转换,反之亦然。
ConvertUtil 类在设置各种页面属性时特别有用,因为例如,英寸是比点更常见的测量单位。
以下代码示例显示如何以英寸为单位指定页面属性:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-.NET | |
Document doc = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
PageSetup pageSetup = builder.PageSetup; | |
pageSetup.TopMargin = ConvertUtil.InchToPoint(1.0); | |
pageSetup.BottomMargin = ConvertUtil.InchToPoint(1.0); | |
pageSetup.LeftMargin = ConvertUtil.InchToPoint(1.5); | |
pageSetup.RightMargin = ConvertUtil.InchToPoint(1.5); | |
pageSetup.HeaderDistance = ConvertUtil.InchToPoint(0.2); | |
pageSetup.FooterDistance = ConvertUtil.InchToPoint(0.2); |