Extract images

Docotic.Pdf Library Help > Samples > Images > Extract images

This sample shows how to extract images from PdfDocument.

Use PdfImage.Save method to extract image from PDF document and save it to a stream or a file.

When saving to a file, you should specify an output file name without extension. PdfImage.Save adds extension based on the image data, saves image and returns full output path.

When saving to a stream, PdfImage.Save method returns format of the image data saved to a stream.

CopyC#
using System.Diagnostics;

namespace BitMiracle.Docotic.Pdf.Samples
{
    public static class ExtractImages
    {
        public static void Main()
        {
            // NOTE: 
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            PdfDocument pdf = new PdfDocument(@"Sample Data\gmail-cheat-sheet.pdf");

            string imageFile = pdf.Images[0].Save("ExtractedImage");
            pdf.Dispose();

            Process.Start(imageFile);
        }
    }
}
CopyVB.NET
Imports System.Diagnostics

Imports BitMiracle.Docotic.Pdf

Namespace BitMiracle.Docotic.Pdf.Samples
    Public NotInheritable Class ExtractImages
        Public Shared Sub Main()
            ' NOTE: 
            ' When used in trial mode, the library imposes some restrictions.
            ' Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            ' for more information.


            Dim pdf As New PdfDocument("Sample Data\gmail-cheat-sheet.pdf")

            Dim imageFile As String = pdf.Images(0).Save("ExtractedImage")
            pdf.Dispose()

            Process.Start(imageFile)
        End Sub
    End Class
End Namespace