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)
Extract the images from the PDF
Declaration
public static Image[] ExtractImages(this PdfPageBase page)
Parameters
Type | Name | Description |
---|---|---|
PdfPageBase | page |
Returns
Type | Description |
---|---|
System.Drawing.Image[] | returns the List of images |
Examples
FileStream input = new FileStream("Input.pdf", FileMode.Open, FileAccess.Read);
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(input);
//Load first page.
PdfPageBase pageBase = loadedDocument.Pages[0];
//Extract images from first page.
Image[] extractedImages = pageBase.ExtractImages();
//close the document
loadedDocument.Close(true);
'Load PDF document.
Dim input As New FileStream("Input.pdf", FileMode.Open, FileAccess.Read)
Dim loadedDocument As New PdfLoadedDocument(input)
'Load first page.
Dim pageBase As PdfPageBase = loadedDocument.Pages(0)
'Extract images from first page.
Dim extractedImages As Image() = pageBase.ExtractImages()
'close the document.
loadedDocument.Close(True)
GetImagesInfo(PdfPageBase)
Declaration
public static PdfImageInfo[] GetImagesInfo(this PdfPageBase page)
Parameters
Type | Name | Description |
---|---|---|
PdfPageBase | page |
Returns
Type | Description |
---|---|
PdfImageInfo[] |
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)