Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Most of the object properties provided in the Aspose.Words API that represent some measurement, such as width or height, margins, and various distances, accept values in points, where 1 inch equals 72 points. Sometimes this is not convenient and points need to be converted to other units.
Aspose.Words provides the ConvertUtil class that provides helper functions to convert between various measurement units. It enables converting inches, pixels and millimeters to points, points to inches and pixels, and converting pixels from one resolution to another. Converting pixels to points and vice versa can be performed at 96 dpi (dots per inch) resolutions or specified dpi resolution.
The ConvertUtil class is especially useful when setting various page properties because, for instance, inches are more common measurement units than points.
The following code example shows how to specify page properties in inches:
Q: How do I convert inches to points?
A: Use ConvertUtil.inch_to_point. The method takes a floating‑point value representing inches and returns the equivalent number of points (1 inch = 72 points).
import aspose.words as aw
inches = 2.5
points = aw.ConvertUtil.inch_to_point(inches)
print(f"{inches} inches = {points} points")
Q: How do I convert points to inches?
A: Call ConvertUtil.point_to_inch. It receives a point value and returns the measurement in inches.
import aspose.words as aw
points = 180
inches = aw.ConvertUtil.point_to_inch(points)
print(f"{points} points = {inches} inches")
Q: How can I convert pixels to points at the default 96 dpi resolution?
A: Use ConvertUtil.pixel_to_point. When you omit the DPI argument, 96 dpi is assumed.
import aspose.words as aw
pixels = 300
points = aw.ConvertUtil.pixel_to_point(pixels) # 96 dpi is used automatically
print(f"{pixels} pixels = {points} points at 96 dpi")
Q: How do I convert points to pixels with a custom DPI?
A: Use ConvertUtil.point_to_pixel and pass the desired DPI value.
import aspose.words as aw
points = 72
dpi = 150
pixels = aw.ConvertUtil.point_to_pixel(points, dpi)
print(f"{points} points = {pixels} pixels at {dpi} dpi")
Q: I get an error saying 'ConvertUtil' has no attribute 'point_to_twip'. Why?
A: The ConvertUtil class does not provide a point_to_twip method. Twips are a legacy unit (1 point = 20 twips) and must be converted manually: multiply the point value by 20.
points = 5
twips = points * 20
print(f"{points} points = {twips} twips")
If you need a dedicated helper, create a small wrapper function that performs this multiplication.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.