горизонтально расположенные полосы: белая, синяя, красная

Извлечение изображений из PDF-файлов на C# и VB.NET

Извлеките все изображения и векторную графику из PDF

using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      // Extract all images from PDF
      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)
      {
        // Rasterize all vector graphics
        f.ImageExtractionOptions.RasterizeComplexGraphics = true;
        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.Save(imageFile);
            System.Diagnostics.Process.Start(imageFile);
          }
        }
      }
    }
  }
}
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample
  Sub Main()
    ' Extract all images from PDF
    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
      ' Rasterize all vector graphics
      f.ImageExtractionOptions.RasterizeComplexGraphics = True
      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.Save(imageFile)
        System.Diagnostics.Process.Start(imageFile)
        Next i
      End If
    End If
  End Sub
End Module

Извлеките все изображения с 1-й страницы PDF-документа на C# и VB.NET

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);
          }
        }
      }
    }
  }
}
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

Извлеките все изображения шириной и высотой более 200px с помощью C# и VB.NET

using System;
using System.IO;
using System.Collections.Generic;
using SautinSoft;

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      // Extract all images with width and height more than 200px
      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)
      {
        // Specify to extract only images which have width and height
        // more than 200px
        f.ImageExtractionOptions.MinSize = new System.Drawing.Size(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.Save(imageFile);
            System.Diagnostics.Process.Start(imageFile);
          }
        }
      }
    }
  }
}
Imports System.IO
Imports System.Drawing.Imaging
Imports System.Collections.Generic
Imports SautinSoft

Module Sample

  Sub Main()
    ' Extract all images with width and height more than 200px
    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
      ' Specify to extract only images which have width and height
      ' more than 200px
      f.ImageExtractionOptions.MinSize = New System.Drawing.Size(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.Save(imageFile)
        System.Diagnostics.Process.Start(imageFile)
        Next i
      End If
    End If
  End Sub
End Module

Другие примеры кода SautinSoft.PdfFocus

PDF в Word PDF в HTML PDF в Img ✦ Image из PDF PDF в Excel PDF в XML PDF в Text PDF во Всё
 ВВЕРХ