轉換測量單位
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); |