menu

Xamarin.Android

  • Code Examples
  • Upgrade Guide
  • User Guide
  • Demos
  • Support
  • Forums
  • Download
Class PdfImageExtractor - Xamarin.Android API Reference | Syncfusion

    Show / Hide Table of Contents

    Class PdfImageExtractor

    Inheritance
    System.Object
    PdfImageExtractor
    Namespace: Syncfusion.Pdf.Exporting
    Assembly: Syncfusion.Pdf.Imaging.Portable.dll
    Syntax
    public static class PdfImageExtractor : Object

    Methods

    ExtractImages(PdfPageBase)

    Extracts images from a PDF document and returns an array of images as a stream.

    Declaration
    public static Stream[] ExtractImages(this PdfPageBase page)
    Parameters
    Type Name Description
    PdfPageBase page
    Returns
    Type Description
    System.IO.Stream[]

    An array of streams, each representing an extracted image from the PDF document.

    Examples
    //Load PDF document.
    FileStream input = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
    PdfLoadedDocument document = new PdfLoadedDocument(input);
    //Gets ImageInfo from the first page.
    Stream[] streams = document.Pages[0].ExtractImages();
    //Gets the Image Boundary location.
    RectangleF imageBounds = imageInfo[0].Bounds;
    //Gets the Image.
    Image image = imageInfo[0].Image;
    //Gets the Image index.
    int imageIndex = imageInfo[0].Index;
    //Closing the PDF document.
    document.Close(true);
    'Load PDF document.
    Dim input As New FileStream("Input.pdf", FileMode.Open, FileAccess.Read)
    Dim document As New PdfLoadedDocument(input)
    'Gets ImageInfo from the first page.
    Dim imageInfo As Stream() = document.Pages(0).ExtractImages();
    'Gets the Image Boundary location.
    Dim imageBounds As RectangleF = imageInfo(0).Bounds
    'Gets the Image.
    Dim image As Image = imageInfo(0).Image
    'Gets the Image index.
    Dim imageIndex As Integer = imageInfo(0).Index
    'Closing the PDF document.
    document.Close(True)
    See Also
    PdfDocument
    PdfPage

    GetImagesInfo(PdfPageBase)

    Gets the information about the extracted image from the PDF page.

    Declaration
    public static PdfImageInfo[] GetImagesInfo(this PdfPageBase page)
    Parameters
    Type Name Description
    PdfPageBase page
    Returns
    Type
    PdfImageInfo[]
    Examples
    //Load PDF document.
    FileStream input = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
    PdfLoadedDocument document = new PdfLoadedDocument(input);
    //Gets ImageInfo from the first page.
    PdfImageInfo[] imageInfo = document.Pages[0].GetImagesInfo();
    //Gets the Image Boundary location.
    RectangleF imageBounds = imageInfo[0].Bounds;
    //Gets the Image.
    Image image = imageInfo[0].Image;
    //Gets the Image index.
    int imageIndex = imageInfo[0].Index;
    //Closing the PDF document.
    document.Close(true);
    'Load PDF document.
    Dim input As New FileStream("Input.pdf", FileMode.Open, FileAccess.Read)
    Dim document As New PdfLoadedDocument(input)
    'Gets ImageInfo from the first page.
    Dim imageInfo As PdfImageInfo() = document.Pages(0).GetImagesInfo()
    'Gets the Image Boundary location.
    Dim imageBounds As RectangleF = imageInfo(0).Bounds
    'Gets the Image.
    Dim image As Image = imageInfo(0).Image
    'Gets the Image index.
    Dim imageIndex As Integer = imageInfo(0).Index
    'Closing the PDF document.
    document.Close(True)
    See Also
    PdfDocument
    PdfPage

    RemoveImage(PdfPageBase, PdfImageInfo)

    Remove the image from the PDF page in the existing PDF document.

    Declaration
    public static void RemoveImage(this PdfPageBase page, PdfImageInfo imageInfo)
    Parameters
    Type Name Description
    PdfPageBase page
    PdfImageInfo imageInfo
    Examples
     //Load an existing PDF.
     PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileName);
     //Load first page.
     PdfPageBase pageBase = loadedDocument.Pages[0];
     //Extract images from first page.        
     PdfImageInfo imageInfo = loadedDocument.Pages[0].ImagesInfo[0];
     //Remove the Image.
    loadedDocument.Pages[0].RemoveImage(imageInfo);
     MemoryStream stream = new MemoryStream();
     //Save the document
     loadedDocument.Save(stream);
     //close the document
    loadedDocument.Close(true);
    'Load an existing PDF
     Dim loadedDocument As PdfLoadedDocument =  New PdfLoadedDocument(fileName) 
     'Load first page.
     Dim pageBase As PdfPageBase = loadedDocument.Pages(0) 
     'Extract images from first page.        
     Dim imageInfo As PdfImageInfo = loadedDocument.Pages(0).ImagesInfo(0) 
     'Remove the Image.
     loadedDocument.Pages(0).RemoveImage(imageInfo)       
     Dim stream As New MemoryStream()
     'Save the document
     loadedDocument.Save(stream)
     'close the document
     loadedDocument.Close(True)        

    ReplaceImage(PdfPageBase, Int32, PdfImage)

    Replace the image at the index position.

    Declaration
    public static void ReplaceImage(this PdfPageBase page, int index, PdfImage image)
    Parameters
    Type Name Description
    PdfPageBase page
    System.Int32 index

    index of an image

    PdfImage image

    The New Replace image

    Examples
     //Load the PDF document
     FileStream input = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
     PdfLoadedDocument doc = new PdfLoadedDocument(input);
     //Create an image instance
     PdfBitmap bmp = new PdfBitmap(new FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read));
     //Replace the first image in the page.
     doc.Pages[0].ReplaceImage(0, bmp);
     MemoryStream stream = new MemoryStream();
     //Save the document
     doc.Save(stream);
     //Close the document
     doc.Close(true);
     'Load the PDF document
     Dim input As New FileStream("Input.pdf", FileMode.Open, FileAccess.Read)
     Dim doc As New PdfLoadedDocument(input)
     Dim input As New FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read)
     'Create an image instance
     Dim bmp As New PdfBitmap(input)
     'Replace the first image in the page.
     doc.Pages(0).ReplaceImage(0, bmp)
     Dim stream As New MemoryStream()
     'Save the document
     doc.Save(stream)
     'Close the document
     doc.Close(True)
    Back to top Generated by DocFX
    Copyright © 2001 - 2025 Syncfusion Inc. All Rights Reserved