Click or drag to resize

PdfFocusCImageExtractionOptions Class

Allows to set properties to extract only specific images from PDF
Inheritance Hierarchy
SystemObject
  SautinSoftPdfFocusCImageExtractionOptions

Namespace: SautinSoft
Assembly: SautinSoft.PdfFocus (in SautinSoft.PdfFocus.dll) Version: 2024.3.28
Syntax
public class CImageExtractionOptions

The PdfFocusCImageExtractionOptions type exposes the following members.

Properties
 NameDescription
Public propertyCode exampleMaxSize Specify maximal size of extracted images in pixels. Default value: null.
Public propertyCode exampleMinSize Specify minimal size of extracted images in pixels. Default value: null.
Public propertyCode exampleRasterizeComplexGraphics Additionally convert all vector graphics to raster images or not. Default value: false.
Top
Example
Extract all images with width and height more than 200px in C#
using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft;

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

            // Extract all images with width and height more than 200px
            SautinSoft.PdfFocus f = new SautinSoft.PdfFocus();

            string pdfFile = Path.GetFullPath(@"..\..\..\simple text.pdf");
            string imageDir = new DirectoryInfo(Directory.GetCurrentDirectory()).CreateSubdirectory("images").FullName;

            List<PdfFocus.PdfImage> pdfImages = null;

            f.OpenPdf(pdfFile);

            if (f.PageCount > 0)
            {
                // Specify to extract only images which have width and height
                // more than 200px
                f.ImageExtractionOptions.MinSize = new SkiaSharp.SKSize(200, 200);

                pdfImages = f.ExtractImages();                

                // 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.Encode(new FileStream(imageFile, FileMode.Create), SkiaSharp.SKEncodedImageFormat.Png, 100);            
                    }
                    System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(imageDir) { UseShellExecute = true });
                }
            }
        }
    }
}
Extract all images with width and height more than 200px in VB.Net
Imports System
Imports System.IO
Imports System.Collections.Generic
Imports SautinSoft

Namespace Sample
    Friend Class Sample
        Shared Sub Main(ByVal args() As String)
              ' Get your free 30-day key here:   
             ' https://sautinsoft.com/start-for-free/

            ' Extract all images with width and height more than 200px
            Dim f As New SautinSoft.PdfFocus()

            Dim pdfFile As String = Path.GetFullPath("..\..\..\simple text.pdf")
            Dim imageDir As String = (New DirectoryInfo(Directory.GetCurrentDirectory())).CreateSubdirectory("images").FullName

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

            f.OpenPdf(pdfFile)

            If f.PageCount > 0 Then
                ' Specify to extract only images which have width and height
                ' more than 200px
                f.ImageExtractionOptions.MinSize = New SkiaSharp.SKSize(200, 200)

                pdfImages = f.ExtractImages()

                ' 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.Encode(New FileStream(imageFile, FileMode.Create), SkiaSharp.SKEncodedImageFormat.Png, 100)
                    Next i
                    System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(imageDir) With {.UseShellExecute = True})
                End If
            End If
        End Sub
    End Class
End Namespace
See Also