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 using ConvertUtil?
A: Use the static method ConvertUtil.inchToPoint. Pass the number of inches and the method returns the equivalent points (1 inch = 72 points).
const aspose = require('aspose.words');
const ConvertUtil = aspose.ConvertUtil;
const inches = 2.5;
const points = ConvertUtil.inchToPoint(inches); // 180 points
Q: Can I convert pixels to points at a custom DPI?
A: Yes. Call ConvertUtil.pixelToPoint with the pixel value and the DPI you want to use. This lets you adapt the conversion to the resolution of your source image.
const pixels = 300;
const dpi = 150; // custom DPI
const points = ConvertUtil.pixelToPoint(pixels, dpi);
Q: Is there a method to convert millimeters to points?
A: ConvertUtil provides millimeterToPoint. Supply the millimeter value and it returns the corresponding points (1 mm ≈ 2.83465 points).
const millimeters = 50;
const points = ConvertUtil.millimeterToPoint(millimeters);
Q: What DPI does ConvertUtil use by default when converting pixels?
A: When you call ConvertUtil.pixelToPoint without specifying a DPI, the method assumes a default of 96 dpi, which is the standard screen resolution. If you need a different DPI, pass it as the second argument.
Q: How can I convert points back to inches?
A: Use the static method ConvertUtil.pointToInch. It takes a point value and returns the measurement in inches.
const points = 144;
const inches = ConvertUtil.pointToInch(points); // 2 inches
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.