Delete images from PDF in C++
Contents
[
Hide
]
Delete the first image resource from the first PDF page using Aspose.PDF for C++.
Delete the first image resource
The PDF must contain page 1 and at least one image resource on that page. This example does not iterate through every page or image.
- Open the input PDF as a Document.
- Select page 1 and retrieve its XImageCollection.
- Call Delete(1) on the image collection.
- Save the PDF with Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Operator.h>
#include <Aspose.PDF.Cpp/OperatorCollection.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
#include <Aspose.PDF.Cpp/Rectangle.h>
#include <Aspose.PDF.Cpp/Resources.h>
#include <Aspose.PDF.Cpp/XImage.h>
#include <Aspose.PDF.Cpp/XImageCollection.h>
#include <system/io/file.h>
using namespace System;
using namespace Aspose::Pdf;
using namespace Aspose::Pdf::Operators;
void DeleteImage(String inputFile, String outputFile)
{
auto document = MakeObject<Document>(inputFile);
document->get_Pages()->idx_get(1)->get_Resources()->get_Images()->Delete(1);
document->Save(outputFile);
}