Saves a specific page of PDF document into image as byte stream

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

Syntax

      
 C#  Visual Basic 
public byte[] ToImage(
	int page
)
Public Function ToImage ( _
	page As Integer _
) As Byte()

Parameters

page
Int32
Page which you want to save as image

Return Value

Image as byte stream in specified ImageFormat - 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

CopyASP.Net - Export PDF to Jpeg in C#
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Result.Text = "";
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.PostedFile.FileName.Length == 0 || FileUpload1.FileBytes.Length == 0)
        {
            Result.Text = "Please select PDF file at first!";
            return;
        }
        Result.Text = "Converting ...";

        SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();
        //this property is necessary only for registered version
        //f.Serial = "XXXXXXXXXXX";

        f.OpenPdf(FileUpload1.FileBytes);

        if (f.PageCount > 0)
        {
            //set image properties
            f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;
            f.ImageOptions.Dpi = 200;

            //Let's convert 1st page from PDF document
            byte[] image = f.ToImage(1);

            //show image
            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = "image/jpeg";
            Response.AddHeader("Content-Disposition:", "attachment; filename=Page1.jpg");
            Response.BinaryWrite(image);
            Response.Flush();
            Response.End();
        }
        else
        {
            Result.Text = "Converting failed!";
        }
    }
}
CopyASP.Net - Export PDF to Jpeg in VB.Net
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports System.IO

Partial Public Class _Default
    Inherits System.Web.UI.Page
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Result.Text = ""
    End Sub
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
        If FileUpload1.PostedFile.FileName.Length = 0 OrElse FileUpload1.FileBytes.Length = 0 Then
            Result.Text = "Please select PDF file at first!"
            Return
        End If

        Dim f As New SautinSoft.PdfFocus()
        'this property is necessary only for registered version
        'f.Serial = "XXXXXXXXXXX"


        f.OpenPdf(FileUpload1.FileBytes)

        If f.PageCount > 0 Then

            'set image properties
            f.ImageOptions.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg
            f.ImageOptions.Dpi = 200
            'Let's convert 1st page from PDF document
            Dim image() As Byte = f.ToImage(1)

            'show image
            Response.Buffer = True
            Response.Clear()
            Response.ContentType = "image/jpeg"
            Response.AddHeader("Content-Disposition:", "attachment; filename=Page1.jpg")
            Response.BinaryWrite(image)
            Response.Flush()
            Response.End()
        Else
            Result.Text = "Converting failed!"
        End If


    End Sub
End Class

See Also