Extract all images from PDF document from specific pages.

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

Syntax

      
 C#  Visual Basic 
public List<PdfFocus..::.PdfImage> ExtractImages(
	int from,
	int to
)
Public Function ExtractImages ( _
	from As Integer, _
	to As Integer _
) As List(Of PdfFocus..::.PdfImage)

Parameters

from
Int32
The starting page for extracting images.
to
Int32
The ending page for extracting images.

Return Value

List with PdfImage objects.
Null - in case of extraction failed.

Examples

CopyExtract all images from 1st PDF page in C#
using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft;

namespace Sample
{
    class Sample
    {
        static void Main(string[] args)
        {
            // Extract all images from 1st PDF page
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            // This property is necessary only for registered version
            // f.Serial = "XXXXXXXXXXX";
            string pdfFile = @"..\..\..\..\..\simple text.pdf";
            string imageDir = Path.GetDirectoryName(pdfFile);

            List<PdfFocus.PdfImage> pdfImages = null;

            f.OpenPdf(pdfFile);

            if (f.PageCount > 0)
            {
                pdfImages = f.ExtractImages(1, 1);                

                // Show all extracted images.
                if (pdfImages != null && pdfImages.Count > 0)
                {

                    for (int i = 0; i < pdfImages.Count; i++)
                    {
                        string imageFile = Path.Combine(imageDir, String.Format("img{0}.png", i + 1));
                        pdfImages[i].Picture.Save(imageFile);
                        System.Diagnostics.Process.Start(imageFile);
                    }
                }
            }
        }
    }
}
CopyExtract all images from 1st PDF page in VB.Net
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

    Sub Main()
        ' Extract all images from 1st PDF page
        Dim f As New SautinSoft.PdfFocus()

        ' This property is necessary only for registered version
        ' f.Serial = "XXXXXXXXXXX";
        Dim pdfFile As String = "..\..\..\..\simple text.pdf"
        Dim imageDir As String = Path.GetDirectoryName(pdfFile)

        Dim pdfImages As List(Of PdfFocus.PdfImage) = Nothing

        f.OpenPdf(pdfFile)

        If f.PageCount > 0 Then
            pdfImages = f.ExtractImages(1, 1)

            ' Show all extracted images.
            If pdfImages IsNot Nothing AndAlso pdfImages.Count > 0 Then

                For i As Integer = 0 To pdfImages.Count - 1
                    Dim imageFile As String = Path.Combine(imageDir, String.Format("img{0}.png", i + 1))
                    pdfImages(i).Picture.Save(imageFile)
                    System.Diagnostics.Process.Start(imageFile)
                Next i
            End If
        End If
    End Sub
End Module

See Also