Convert a Document to an Image
Sometimes it is required to get an image instead of documents in other formats, such as DOCX or PDF. For example, you need to add a preview of any document page to your website or application or create a “scan” of a document to send an invoice. This is when you may need to convert a document in any supported load format to an image, again, in any supported save format.
Convert to Image Format
As with all conversion examples already described, you need to create a new document or load an existing one in any supported format, make the necessary changes, and save it in any available image format, for example, JPEG, PNG, or BMP.
The following code example shows how to convert DOCX to JPEG:
Specify Save Options when Converting to an Image
Aspose.Words provides you with the ImageSaveOptions class, which gives more control over how documents are saved in various image formats. Some properties of this class inherit or overload properties of base classes such as FixedPageSaveOptions or SaveOptions, but there are also options specific to saving images.
It is possible to specify the pages to be converted to image format using the PageSet property. For example, it can be applied if you only need a preview for the first or for a definite page.
It is also possible to control the output image quality and pixel format using the following properties – HorizontalResolution, VerticalResolution, Resolution, Scale, PixelFormat, as well as set up image color settings, using the following properties – ImageBrightness, ImageColorMode, ImageContrast, PaperColor.
There are also properties that apply to a certain format, for example, JpegQuality or TiffCompression.
The following code example shows how to create a preview of the first document page with applying some additional settings: