Save document pages as Images using C# and .NET


Load a document and save all pages as separate PNG & Jpeg images.

separate%20pages%20as%20images

Complete code

using System.IO;
using SautinSoft.Document;
using SkiaSharp;

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

            SeparateDocumentToImagePages();
        }
        /// <summary>
        /// Load a document and save all pages as separate PNG & Jpeg images.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/pagination-save-document-pages-as-png-jpg-jpeg-net-csharp-vb.php
        /// </remarks>
        static void SeparateDocumentToImagePages()
        {
            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];
                Directory.CreateDirectory(folderPath);

                // Save the bitmap to PNG and JPEG.
                page.Save(folderPath + @"\Page (PNG) - " + (i + 1).ToString() + ".png", new ImageSaveOptions { DpiX = 300, DpiY = 300, Format = ImageSaveFormat.Png});
                page.Save(folderPath + @"\Page (Jpeg) - " + (i + 1).ToString() + ".jpeg", new ImageSaveOptions { DpiX = 300, DpiY = 300, Format = ImageSaveFormat.Jpeg});
            }
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(folderPath) { UseShellExecute = true });
        }
    }
}

Download

Imports System.IO
Imports SautinSoft.Document

Namespace Example
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			SeparateDocumentToImagePages()
		End Sub
                ''' Get your free trial key here:   
                ''' https://sautinsoft.com/start-for-free/
		''' <summary>
		''' Load a document and save all pages as separate PNG & Jpeg images.
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/pagination-save-document-pages-as-png-jpg-jpeg-net-csharp-vb.php
		''' </remarks>
		Private Shared Sub SeparateDocumentToImagePages()
			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)
				Directory.CreateDirectory(folderPath)

				' Save the each page as Bitmap.
				Dim dpi As ImageSaveOptions = New ImageSaveOptions
				dpi.DpiX = 300
				dpi.DpiY = 300

				' Save to PNG and JPEG.
				page.Save(folderPath & "\Page (PNG) - " & (i + 1).ToString() & ".png", New ImageSaveOptions With {.Format = ImageSaveFormat.Png, .DpiX = 300, .DpiY = 300})
				page.Save(folderPath & "\Page (Jpeg) - " & (i + 1).ToString() & ".jpg", New ImageSaveOptions With {.Format = ImageSaveFormat.Jpeg, .DpiX = 300, .DpiY = 300})
			Next i
			System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(folderPath) With {.UseShellExecute = True})
		End Sub
	End Class
End Namespace

Download


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.