Working with images using various options
Essential® PDF supports both raster and vector images.
Images are supported through the PdfImage class, which is an abstract base class that provides the common functionality for PdfBitmap and PdfMetafile classes.
Inserting an image in a new document
The following raster images are supported in Essential® PDF.
- BMP
- JPEG
- JPEG with Exif standard
- GIF
- PNG
- TIFF
- ICO and ICON
You can load image streams, files on disk, and use System.Drawing.Bitmap objects to draw the images through the DrawImage method of the PdfGraphics class.
NOTE
For using image formats other than PNG and JPEG in ASP.NET Core, you need to include the Syncfusion.Pdf.Imaging.Net.Core package in your project. This package provides the necessary support for handling other raster image formats like BMP, GIF, TIFF, and ICO.
The following code snippet shows how to add a file from disk to the PDF document.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk
FileStream imageStream = new FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read);
PdfBitmap image = new PdfBitmap(imageStream);
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Add a page to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
'Create a new PDF document
Dim doc As New PdfDocument()
'Add a page to the document
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document
doc.Save("Output.pdf")
'Close the document
doc.Close(True)You can download a complete working sample from GitHub.
Inserting an image in an existing document
You can also add images into an existing PDF document using the below code snippet.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
//Load the PDF document.
PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf");
//Get first page from document
PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage;
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk
FileStream imageStream = new FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read);
PdfBitmap image = new PdfBitmap(imageStream);
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
//Load a PDF document
PdfLoadedDocument doc = new PdfLoadedDocument("input.pdf");
//Get first page from document
PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage;
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk
PdfBitmap image = new PdfBitmap("Autumn Leaves.jpg");
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Parsing
'Load a PDF document
Dim doc As New PdfLoadedDocument("input.pdf")
'Get first page from document
Dim page As PdfLoadedPage = TryCast(doc.Pages(0), PdfLoadedPage)
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image from the disk
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document
doc.Save("Output.pdf")
'Close the document
doc.Close(True)To add image from stream, use the below code snippet.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
//Load the PDF document.
PdfLoadedDocument doc = new PdfLoadedDocument("Input.pdf");
//Get first page from document
PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage;
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image from the disk
FileStream imageStream = new FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read);
PdfBitmap image = new PdfBitmap(imageStream);
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
//Load a PDF document
PdfLoadedDocument doc = new PdfLoadedDocument("input.pdf");
//Get first page from document
PdfLoadedPage page = doc.Pages[0] as PdfLoadedPage;
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the image
Stream imageStream = File.OpenRead("Autumn Leaves.jpg");
//Load the image from the stream
PdfBitmap image = new PdfBitmap(imageStream);
//Draw the image
graphics.DrawImage(image, 0, 0);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports Syncfusion.Pdf.Parsing
'Load a PDF document
Dim doc As New PdfLoadedDocument("input.pdf")
'Get first page from document
Dim page As PdfLoadedPage = TryCast(doc.Pages(0), PdfLoadedPage)
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the image
Dim imageStream As Stream = File.OpenRead("Autumn Leaves.jpg")
'Load the image from the stream
Dim image As New PdfBitmap(imageStream)
'Draw the image
graphics.DrawImage(image, 0, 0)
'Save the document
doc.Save("Output.pdf")
'Close the document
doc.Close(True)You can download a complete working sample from GitHub.
Inserting a vector image
Essential® PDF supports adding Metafile vector image. During the insertion, Metafile graphics will be transformed to native PDF graphics that supports text selection and searching. The following types of Metafiles are supported in Essential® PDF.
- EMF only
- EMF plus
- EMF plus dual
- WMF
PdfMetafile class is used to load EMF images. Additionally the PdfMetafileLayoutFormat class allows you to prevent text and image split across pages in the PDF document.
The following code illustrate this,
//PDF doesn't support inserting a vector image C#.NET Cross platforms.using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
using System.Drawing;
//Create a PDF Document
PdfDocument doc = new PdfDocument();
//Add pages to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Create the layout format
PdfMetafileLayoutFormat format = new PdfMetafileLayoutFormat();
//Split text and image between pages
format.SplitImages = true;
format.SplitTextLines = true;
//Create a Metafile instance
PdfMetafile metaChart = new PdfMetafile("MetaChart.emf");
//Draw the Metafile in the page
metaChart.Draw(page, PointF.Empty, format);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Pdf.Graphics
Imports System.Drawing
'Create a PDF Document
Dim doc As New PdfDocument()
'Add pages to the document
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Create the layout format
Dim format As New PdfMetafileLayoutFormat()
'Split text and image between pages
format.SplitImages = True
format.SplitTextLines = True
'Create a Metafile instance
Dim metaChart As New PdfMetafile("MetaChart.emf")
'Draw the Metafile in the page
metaChart.Draw(page, PointF.Empty, format)
'Save the document
doc.Save("Output.pdf")
'Close the document
doc.Close(True)You can download a complete working sample from GitHub.
Working with image masking
Essential® PDF supports image masking through the PdfImageMask class.
The following code illustrate shows how to add a mask to TIFF image.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a PDF document
PdfDocument doc = new PdfDocument();
//Add pages to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the TIFF image
FileStream imageStream = new FileStream("image.tif", FileMode.Open, FileAccess.Read);
PdfTiffImage image = new PdfTiffImage(imageStream);
//Create masking image
FileStream maskStream = new FileStream("mask.bmp", FileMode.Open, FileAccess.Read);
PdfImageMask mask = new PdfImageMask(new PdfTiffImage(maskStream));
image.Mask = mask;
//Draw the image
graphics.DrawImage(image, 0, 0);
///Creating the stream object
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a PDF document
PdfDocument doc = new PdfDocument();
//Add pages to the document
PdfPage page = doc.Pages.Add();
//Create PDF graphics for the page
PdfGraphics graphics = page.Graphics;
//Load the TIFF image
PdfBitmap image = new PdfBitmap("image.tif");
//Create masking image
PdfImageMask mask = new PdfImageMask(new PdfBitmap("mask.bmp"));
image.Mask = mask;
//Draw the image
graphics.DrawImage(image, 0, 0);
//Saves the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
'Create a PDF document
Dim doc As New PdfDocument()
'Add pages to the document
Dim page As PdfPage = doc.Pages.Add()
'Create PDF graphics for the page
Dim graphics As PdfGraphics = page.Graphics
'Load the TIFF image
Dim image As New PdfBitmap("image.tif")
'Create masking image
Dim mask As New PdfImageMask(New PdfBitmap("mask.bmp"))
image.Mask = mask
'Draw the image
graphics.DrawImage(image, 0, 0)
'Saves the document
doc.Save("Output.pdf")
'Close the document
doc.Close(True)You can download a complete working sample from GitHub.
NOTE
- Essential PDF supports image masking with Syncfusion.Pdf.Imaging.Net.Core package reference in ASP.NET Core.
Replacing Images in an existing PDF document
Essential® PDF allows you to replace images in an existing document. The ReplaceImage method of the PdfLoadedPage allows you to replace an image.
using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
//Load the PDF document.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Create an image instance.
FileStream imageStream = new FileStream(Path.GetFullPath("Autumn Leaves.jpg"), FileMode.Open, FileAccess.Read);
PdfBitmap bmp = new PdfBitmap(imageStream);
//Replace the first image in the page
loadedDocument.Pages[0].ReplaceImage(0, bmp);
//Save the document
loadedDocument.Save("Output.pdf");
//Close the document
loadedDocument.Close(true);using Syncfusion.Pdf.Graphics;
using Syncfusion.Pdf.Parsing;
//Load the PDF document
PdfLoadedDocument doc = new PdfLoadedDocument(@"image.pdf");
//Create an image instance
PdfBitmap image = new PdfBitmap(@"Autumn Leaves.jpg");
//Replace the first image in the page
doc.Pages[0].ReplaceImage(0, image);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);Imports Syncfusion.Pdf.Parsing
Imports Syncfusion.Pdf.Graphics
'Load the PDF document
Dim doc As New PdfLoadedDocument("image.pdf")
'Create an image instance
Dim image As New PdfBitmap("Autumn Leaves.jpg")
'Replace the first image in the page
doc.Pages(0).ReplaceImage(0, image)
'Save the document
doc.Save("Output.pdf")
'Close the document
doc.Close(True)You can download a complete working sample from GitHub.
Image Pagination
You can allow a large image to paginate across multiple pages in the PDF document. This can be done through the PdfLayoutFormat class as shown below.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create Document
PdfDocument doc = new PdfDocument();
//Add new page
PdfPage page = doc.Pages.Add();
//Load a bitmap
FileStream imageStream = new FileStream("Autumn Leaves.jpg", FileMode.Open, FileAccess.Read);
PdfBitmap image = new PdfBitmap(imageStream);
//Set layout property to make the element break across the pages
PdfLayoutFormat format = new PdfLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
//Draw image
image.Draw(page, 20, 400, format);
//Save the PDF
doc.Save("output.pdf");
doc.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create Document
PdfDocument doc = new PdfDocument();
//Add new page
PdfPage page = doc.Pages.Add();
//Load a bitmap
PdfBitmap image = new PdfBitmap("input.jpg");
//Set layout property to make the element break across the pages
PdfLayoutFormat format = new PdfLayoutFormat();
format.Break = PdfLayoutBreakType.FitPage;
format.Layout = PdfLayoutType.Paginate;
//Draw image
image.Draw(page,20,400, format);
//Save the PDF
doc.Save("output.pdf");
doc.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
'Create Document
Dim doc As New PdfDocument()
'Add new page
Dim page As PdfPage = doc.Pages.Add()
'Load a bitmap
Dim image As New PdfBitmap("input.jpg")
'Set layout property to make the element break across the pages
Dim format As New PdfLayoutFormat()
format.Break = PdfLayoutBreakType.FitPage
format.Layout = PdfLayoutType.Paginate
'Draw image
image.Draw(page, 20, 400, format)
'Save the PDF
doc.Save("output.pdf")
doc.Close(True)You can download a complete working sample from GitHub.
Applying transparency and rotation to the image
You can add transparency and rotation to the image using SetTransparency and RotateTransform methods of PdfGraphics respectively. This is explained in the below code snippet.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create Document
PdfDocument doc = new PdfDocument();
//Add a new page
PdfPage page = doc.Pages.Add();
//Load a image as stream
FileStream imageStream = new FileStream("input.jpg", FileMode.Open, FileAccess.Read);
//Load a bitmap
PdfBitmap image = new PdfBitmap(imageStream);
//save the current graphics state
PdfGraphicsState state = page.Graphics.Save();
//Translate the coordinate system to the required position
page.Graphics.TranslateTransform(20, 100);
//Apply transparency
page.Graphics.SetTransparency(0.5f);
//Rotate the coordinate system
page.Graphics.RotateTransform(-45);
//Draw image
image.Draw(page, 0, 0);
//Restore the graphics state
page.Graphics.Restore(state);
//Save the PDF
doc.Save("output.pdf");
doc.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create Document
PdfDocument doc = new PdfDocument();
//Add a new page
PdfPage page = doc.Pages.Add();
//Load a bitmap
PdfBitmap image = new PdfBitmap("input.jpg");
//save the current graphics state
PdfGraphicsState state = page.Graphics.Save();
//Translate the coordinate system to the required position
page.Graphics.TranslateTransform(20, 100);
//Apply transparency
page.Graphics.SetTransparency(0.5f);
//Rotate the coordinate system
page.Graphics.RotateTransform(-45);
//Draw image
image.Draw(page, 0, 0);
//Restore the graphics state
page.Graphics.Restore(state);
//Save the PDF
doc.Save("output.pdf");
doc.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
'Create Document
Dim doc As New PdfDocument()
'Add a new page
Dim page As PdfPage = doc.Pages.Add()
'Load a bitmap
Dim image As New PdfBitmap("input.jpg")
'save the current graphics state
Dim state As PdfGraphicsState = page.Graphics.Save()
'Translate the coordinate system to the required position
page.Graphics.TranslateTransform(20, 100)
'Apply transparency
page.Graphics.SetTransparency(0.5F)
'Rotate the coordinate system
page.Graphics.RotateTransform(-45)
' Draw image
image.Draw(page, 0, 0)
'Restore the graphics state
page.Graphics.Restore(state)
'Save the PDF
doc.Save("output.pdf")
doc.Close(True)You can download a complete working sample from GitHub.
Unit conversion in image position
The PdfUnitConverter class provides precise measurement conversion capabilities for PDF layouts. When positioning images in a PDF document, the converter translates pixel dimensions to PDF points, enabling millimeter-perfect placement and sizing. This ensures images maintain their aspect ratio while rendering at exact locations and filling designated spaces like rectangles.
The code snippet to illustrate the same is given below.
using Syncfusion.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
using (FileStream stream = new FileStream("Image.png", FileMode.Open, FileAccess.Read))
{
//Load the image from the disk
PdfBitmap image = new PdfBitmap(stream);
//Add the first section to the PDF document
PdfSection section = document.Sections.Add();
//Initialize unit converter
PdfUnitConverter converter = new PdfUnitConverter();
//Convert the image size from pixel to points
SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Point);
//Set section size based on the image size
section.PageSettings.Size = size;
// Set section orientation based on the image size (by default Portrait)
if (image.Width > image.Height)
section.PageSettings.Orientation = PdfPageOrientation.Landscape;
//Set a margin for the section
section.PageSettings.Margins.All = 0;
//Add a page to the section
PdfPage page = section.Pages.Add();
//Draw image
page.Graphics.DrawImage(image, 0, 0);
//Save the document
document.Save("Output.pdf");
}
}using System.Drawing;
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a new PDF document
using (PdfDocument document = new PdfDocument())
{
using (FileStream stream = new FileStream("Image.png", FileMode.Open, FileAccess.Read))
{
//Load the image from the disk
PdfBitmap image = new PdfBitmap(stream);
//Add the first section to the PDF document
PdfSection section = document.Sections.Add();
//Initialize unit converter
PdfUnitConverter converter = new PdfUnitConverter();
//Convert the image size from pixel to points
SizeF size = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Point);
//Set section size based on the image size
section.PageSettings.Size = size;
// Set section orientation based on the image size (by default Portrait)
if (image.Width > image.Height)
section.PageSettings.Orientation = PdfPageOrientation.Landscape;
//Set a margin for the section
section.PageSettings.Margins.All = 0;
//Add a page to the section
PdfPage page = section.Pages.Add();
//Draw image
page.Graphics.DrawImage(image, 0, 0);
//Save the document
document.Save("Output.pdf");
}
}Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
Imports System.Drawing
Module Program
Sub Main()
' Create a new PDF document
Using document As New PdfDocument()
' Load the image from disk
Using stream As New FileStream("Image.png", FileMode.Open, FileAccess.Read)
Dim image As New PdfBitmap(stream)
' Add a section to the PDF document
Dim section As PdfSection = document.Sections.Add()
' Initialize unit converter
Dim converter As New PdfUnitConverter()
' Convert image size from pixels to points
Dim size As SizeF = converter.ConvertFromPixels(image.PhysicalDimension, PdfGraphicsUnit.Point)
' Set section size based on image size
section.PageSettings.Size = size
' Set orientation to landscape if image is wider than tall
If image.Width > image.Height Then
section.PageSettings.Orientation = PdfPageOrientation.Landscape
End If
' Remove margins
section.PageSettings.Margins.All = 0
' Add a page to the section
Dim page As PdfPage = section.Pages.Add()
' Draw the image at position (0, 0)
page.Graphics.DrawImage(image, 0, 0)
' Save the document
document.Save("Output.pdf")
End Using
End Using
End Sub
End ModuleYou can download a complete working sample from GitHub.
Converting multi page TIFF to PDF
Multi frame TIFF image can be converted to PDF document. This can be done by accessing each frame of the multi frame TIFF image and rendering it in each page of the PDF document using PdfBitmap class.
The code snippet to illustrate the same is given below.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a new PDF document
PdfDocument doc = new PdfDocument();
//Set page margins
doc.PageSettings.Margins.All = 0;
//Load the multi frame TIFF image from the disk
FileStream imageStream = new FileStream("image.tiff", FileMode.Open, FileAccess.Read);
PdfTiffImage tiffImage = new PdfTiffImage(imageStream);
//Get the frame count
int frameCount = tiffImage.FrameCount;
//Access each frame and draw into the page
for (int i = 0; i < frameCount; i++)
{
PdfPage page = doc.Pages.Add();
PdfGraphics graphics = page.Graphics;
tiffImage.ActiveFrame = i;
graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
}
//Save and close the document
pdfDocument.Save("Sample.pdf");
pdfDocument.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Graphics;
//Create a PDF document
PdfDocument pdfDocument = new PdfDocument();
//Set page margins
pdfDocument.PageSettings.Margins.All = 0;
//Load multi frame TIFF image
PdfBitmap tiffImage = new PdfBitmap("image.tiff");
//Get the frame count
int frameCount = tiffImage.FrameCount;
//Access each frame and draw into the page
for (int i = 0; i < frameCount; i++)
{
PdfPage page = pdfDocument.Pages.Add();
PdfGraphics graphics = page.Graphics;
tiffImage.ActiveFrame = i;
graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height);
}
//Save and close the document
pdfDocument.Save("Sample.pdf");
pdfDocument.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Graphics
'Create a PDF document
Dim pdfDocument As New PdfDocument()
'Set page margins
pdfDocument.PageSettings.Margins.All = 0
'Load multi frame TIFF image
Dim tiffImage As New PdfBitmap("image.tiff")
'Get the frame count
Dim frameCount As Integer = tiffImage.FrameCount
'Access each frame and draw into the page
For i As Integer = 0 To frameCount - 1
Dim page As PdfPage = pdfDocument.Pages.Add()
Dim graphics As PdfGraphics = page.Graphics
tiffImage.ActiveFrame = i
graphics.DrawImage(tiffImage, 0, 0, page.GetClientSize().Width, page.GetClientSize().Height)
Next
'Save and close the document
pdfDocument.Save("Sample.pdf")
pdfDocument.Close(True)You can download a complete working sample from GitHub.
NOTE
- Essential PDF supports converting TIFF to PDF with Syncfusion.Pdf.Imaging.Net.Core package reference in ASP.NET Core.
Remove Images
The RemoveImage method of the page collection allows you to remove an image. You can remove images from an existing document using Essential® PDF.
The code snippet to illustrate the same is given below.
using Syncfusion.Pdf;
using Syncfusion.Pdf.Exporting;
using Syncfusion.Pdf.Parsing;
//Load an existing PDF.
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("Input.pdf");
//Load the first page.
PdfPageBase pageBase = loadedDocument.Pages[0];
//Extract images from the first page.
PdfImageInfo[] imageInfo = loadedDocument.Pages[0].GetImagesInfo();
//Remove the Image.
pageBase.RemoveImage(imageInfo[0]);
//Save and close the document
loadedDocument.Save("Sample.pdf");
loadedDocument.Close(true);using Syncfusion.Pdf;
using Syncfusion.Pdf.Exporting;
using Syncfusion.Pdf.Parsing;
//Load a PDF document
PdfLoadedDocument doc = new PdfLoadedDocument("input.pdf");
//Load the first page
PdfPageBase pageBase = doc.Pages[0];
//Extract images from the first page
PdfImageInfo imageInfo = pageBase.ImagesInfo[0];
//Remove the Image
pageBase.RemoveImage(imageInfo);
//Save the document
doc.Save("Output.pdf");
//Close the document
doc.Close(true);Imports Syncfusion.Pdf
Imports Syncfusion.Pdf.Parsing
'Load an existing PDF
Dim loadedDocument As PdfLoadedDocument = New PdfLoadedDocument("input.pdf")
'Load the first page
Dim pageBase As PdfPageBase = loadedDocument.Pages(0)
'Extract images from the first page
Dim imageInfo As PdfImageInfo = pageBase.ImagesInfo(0)
'Remove the Image
pageBase.RemoveImage(imageInfo)
'Save the document
loadedDocument.Save("Output.pdf")
'Close the document
loadedDocument.Close(True)You can download a complete working sample from GitHub.
NOTE
- Essential PDF supports remove image from the existing PDF document with Syncfusion.Pdf.Imaging.Net.Core package reference in ASP.NET Core.