This sample shows how to extract images from PdfDocument.
Use PdfImage.Save method to save image from PDF document 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.
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. string imageFile; using (PdfDocument pdf = new PdfDocument(@"Sample Data\gmail-cheat-sheet.pdf")) imageFile = pdf.Images[0].Save("ExtractedImage"); Process.Start(imageFile); } } }
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 imageFile As String Using pdf As New PdfDocument("Sample Data\gmail-cheat-sheet.pdf") imageFile = pdf.Images(0).Save("ExtractedImage") End Using Process.Start(imageFile) End Sub End Class End Namespace