HTML JPG PDF XML DOCX
  Product Family
PDF

Remove Image from PDF in .NET SDK

Delete a Images from a PDF Document using Cloud .NET SDK

Get Started

How to delete Images from PDF via .NET SDK

To delete images from PDF via Cloud .NET SDK, we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.

Package Manager Console Command


     
    PM> Install-Package Aspose.Pdf-Cloud
     
     

Steps to delete images using .NET

Aspose.PDF Cloud developers can easily load & delete images from PDF in just a few lines of code.

  1. Initialize the Aspose PDF API
  2. Upload the PDF Document to Cloud Storage
  3. Deletes image by id from the PDF file in the cloud storage.
  4. Download the result if needed it
 

Remove Images from PDF using .NET


    public async Task DeleteImage()
    {
        const string LOCAL_FOLDER = "C:\\Samples";
        const string REMOTE_TEMP_FOLDER = "TempPdfCloud";
        const string PDF_DOCUMENT = "sample.pdf";
        const string PDF_OUTPUT = "output_sample_images_delete.pdf";
        const string IMAGE_ID =  "IMAGE_ID_VALUE";

        // Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required). 
        pdfApi = new PdfApi(AppSecret, AppSid);

        using (var file = File.OpenRead(Path.Combine(LOCAL_FOLDER, PDF_DOCUMENT)))
        {
            FilesUploadResult response = await pdfApi.UploadFileAsync(Path.Combine(REMOTE_TEMP_FOLDER, PDF_DOCUMENT), file);
            if (response == null)
                Console.WriteLine("UploadFile(): Unexpected error - no response!");
            else if (response.Errors != null && response.Errors.Count > 0)
                foreach (var error in response.Errors)
                    Console.WriteLine("UploadFile(): {0} -> {1}", [error.Code, error.Message]);
                else
                    Console.WriteLine("UploadFile(): File '{0}' successfully uploaded.", PDF_DOCUMENT);
        }

        AsposeResponse response = await pdfApi.DeleteImageAsync(PDF_DOCUMENT, IMAGE_ID, folder: REMOTE_TEMP_FOLDER);

        if (response == null)
            Console.WriteLine("ImagesDelete(): Unexpected error!");
        else if (response.Code < 200 || response.Code > 299)
            Console.WriteLine("ImagesDelete(): Failed to remove image from the document.");
        else {
            Console.WriteLine("ImagesDelete(): image '{0}' successfully removed from the document '{1}.", IMAGE_ID, PDF_DOCUMENT);

            await (await pdfApi.DownloadFileAsync(Path.Combine(REMOTE_TEMP_FOLDER, PDF_DOCUMENT)))
                .CopyToAsync(File.Create(Path.Combine(LOCAL_FOLDER, PDF_OUTPUT)));

            Console.WriteLine("DownloadFile(): File '{0}' successfully downloaded.", PDF_OUTPUT);
        }
    }
 

Work with Images in PDF

Images often contribute significantly to the size of a PDF. Removing them can make the document smaller and easier to share, especially in email or online uploads. Images may contain sensitive information, such as personal photos or proprietary visuals. Removing them ensures the document respects privacy or confidentiality requirements. Removing images from a PDF is a strategic step in ensuring the document is optimized for specific use cases, whether it’s for storage, sharing, or readability. Delete the Images from PDF documents with Aspose.PDF Cloud .NET SDK.

With our .NET library you can:

  • Add PDF document’s header & footer in text or image format.
  • Add tables & stamps (text or image) to PDF documents.
  • Append multiple PDF documents to an existing file.
  • Work with PDF attachments, annotations, & form fields.
  • Apply encryption or decryption to PDF documents & set a password.
  • Delete all stamps & tables from a page or entire PDF document.
  • Delete a specific stamp or table from the PDF document by its ID.
  • Replace single or multiple instances of text on a PDF page or from the entire document.
  • Extensive support for converting PDF documents to various other file formats.
  • Extract various elements of PDF files & make PDF documents optimized.
  • You can try out our free App to change image dimensions in PDF files online and test the functionality.