Saves a specific page of PDF document into standard Image object

Namespace:  SautinSoft
Assembly:  SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 6.6.9.7 (6.6.9.7)

Syntax

      
 C#  Visual Basic 
public Image ToDrawingImage(
	int page
)
Public Function ToDrawingImage ( _
	page As Integer _
) As Image

Parameters

page
Int32
Page which you want to save as image

Return Value

Image object - converting successfully
null - converting failed

Remarks

To start the process, please download the most fresh version of PDF Focus .Net.

Before converting you may set various image properties using the property ImageOptions. For example, set:
  • Dpi - image resolution in dots per inch. Default value: 120
  • ImageFormat - format for produced images as standard ImageFormat. Default value: Png
  • ColorDepth - color depth or bit depth is the number of bits used to represent the color of a single pixel. Default value: 24 bit RGB


Examples

CopyConvert custom PDF page to System.Drawing.Image object in C#
using System;
using System.IO;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            //Convert custom PDF page to Image object
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
            //this property is necessary only for registered version
            //f.Serial = "XXXXXXXXXXX";

            string pdfPath = @"..\..\..\..\..\simple text.pdf";
            string imagePath = Path.ChangeExtension(pdfPath, ".png");

            f.OpenPdf(pdfPath);

            if (f.PageCount > 0)
            {
                //Let's convert 1st page into System.Drawing.Image object, 120 dpi
                f.ImageOptions.Dpi = 120;
                System.Drawing.Image img = f.ToDrawingImage(1);

                //Save to file
                if (img != null)
                {
                    img.Save(imagePath);
                    System.Diagnostics.Process.Start(imagePath);
                }
            }
        }
    }
}
CopyConvert custom PDF page to System.Drawing.Image object in VB.Net
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

    Sub Main()
        'Convert custom PDF page to Image object
        Dim f As New SautinSoft.PdfFocus()
        'this property is necessary only for registered version
        'f.Serial = "XXXXXXXXXXX";


        Dim pdfPath As String = "..\..\..\..\simple text.pdf"
        Dim imagePath As String = Path.ChangeExtension(pdfPath, ".png")

        f.OpenPdf(pdfPath)

        If f.PageCount > 0 Then
            'Let's convert 1st page into System.Drawing.Image object, 120 dpi
            f.ImageOptions.Dpi = 120
            Dim img As System.Drawing.Image = f.ToDrawingImage(1)

            'Save to file
            If img IsNot Nothing Then
                img.Save(imagePath)
                System.Diagnostics.Process.Start(imagePath)
            End If
        End If
    End Sub
End Module

See Also