Click or drag to resize

DocumentPageRasterize(ImageSaveOptions) Method

Rasterizes the document page to SKBitmap. The default color background is white.

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.1.24
Syntax
public SKBitmap Rasterize(
	ImageSaveOptions options
)

Parameters

options  ImageSaveOptions

Return Value

SKBitmap
The pixel-based image.
Example

See Developer Guide: Load DOCX a document and save all pages as images

Load DOCX a document and save all pages as images in C#
using System;
using System.IO;
using System.Runtime.Intrinsics.Arm;
using SautinSoft.Document;
using SkiaSharp;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            SaveToImage();
        }
        /// <summary>
        /// Loads a document and saves all pages as images.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/save-document-as-image-net-csharp-vb.php
        /// </remarks>
        static void SaveToImage()
        {
            string filePath = @"..\..\..\example.docx";
            DocumentCore dc = DocumentCore.Load(filePath);
            string folderPath = Path.GetFullPath(@"Result-files");

            DocumentPaginator dp =  dc.GetPaginator();

            for (int i = 0; i < dp.Pages.Count; i++)
            {
                DocumentPage page = dp.Pages[i];
                // For example, set DPI: 72, Background: White.

                // To get high-quality image, lets set 72 dpi.
                var DPI = new ImageSaveOptions();
                DPI.DpiX = 72;
                DPI.DpiY = 72;

                // Rasterize/convert the page into PNG image.
                SKBitmap image = page.Rasterize(DPI, SautinSoft.Document.Color.White);

                Directory.CreateDirectory(folderPath);
                image.Encode(new FileStream(folderPath + @"\Page - " + i.ToString() + ".png", FileMode.Create), SkiaSharp.SKEncodedImageFormat.Png, 100);

            }
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(folderPath) { UseShellExecute = true });
        }
    }
}
Load DOCX a document and save all pages as images in VB.Net
Imports System
Imports System.IO
Imports System.Runtime.Intrinsics.Arm
Imports SautinSoft.Document
Imports SkiaSharp


Module Sample
    Sub Main()
        SaveToImage()
    End Sub
    ''' Get your free 30-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Loads a document and saves all pages as images.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/save-document-as-image-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToImage()
        Dim filePath As String = "..\..\..\example.docx"
        Dim dc As DocumentCore = DocumentCore.Load(filePath)
        Dim folderPath As String = Path.GetFullPath("Result-files")

        Dim dp As DocumentPaginator = dc.GetPaginator()

        For i As Integer = 0 To dp.Pages.Count - 1
            Dim page As DocumentPage = dp.Pages(i)
            ' For example, set DPI: 72, Background: White.

            Dim dpi As ImageSaveOptions = New ImageSaveOptions()
            dpi.DpiX = 72
            dpi.DpiY = 72
            Dim image As SKBitmap = page.Rasterize(DPI, SautinSoft.Document.Color.White)
            Directory.CreateDirectory(folderPath)
            image.Encode(New FileStream(folderPath + "\Page - " + i.ToString() + ".png", FileMode.Create), SkiaSharp.SKEncodedImageFormat.Png, 100)

        Next i
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(folderPath) With {.UseShellExecute = True})
    End Sub
End Module
See Also