在测量单位之间转换
Contents
[
Hide
]
Aspose.WordsAPI中提供的大多数表示某些度量的对象属性(如宽度或高度、边距和各种距离)都接受以点为单位的值,其中1英寸等于72点。 有时这不方便,需要将积分转换为其他单位。
Aspose.Words提供ConvertUtil类,该类提供帮助函数以在各种测量单位之间进行转换。 它可以将英寸,像素和毫米转换为点,点转换为英寸和像素,并将像素从一种分辨率转换为另一种分辨率。将像素转换为点,反之亦然,可以在96dpi(每英寸点数)分辨率或指定的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-C | |
System::SharedPtr<Document> doc = System::MakeObject<Document>(); | |
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc); | |
System::SharedPtr<PageSetup> pageSetup = builder->get_PageSetup(); | |
pageSetup->set_TopMargin(ConvertUtil::InchToPoint(1.0)); | |
pageSetup->set_BottomMargin(ConvertUtil::InchToPoint(1.0)); | |
pageSetup->set_LeftMargin(ConvertUtil::InchToPoint(1.5)); | |
pageSetup->set_RightMargin(ConvertUtil::InchToPoint(1.5)); | |
pageSetup->set_HeaderDistance(ConvertUtil::InchToPoint(0.2)); | |
pageSetup->set_FooterDistance(ConvertUtil::InchToPoint(0.2)); |