Delete Images from PDF File using C++
Contents
[
Hide
]
To delete an image from a PDF file:
- Create a Document object and open the input PDF file.
- Get the Page that holds the image from the Document object’s Pages collection.
- Images are held in the Images collection, found in the page’s Resources collection.
- Delete an image with the Images collection’s Delete method.
- Saved the output like using the Document object’s Save method.
The following code snippet shows how to delete an image from a PDF file.
void WorkingWithImages::DeleteImagesFromPDFFile()
{
String _dataDir("C:\\Samples\\");
// Open document
auto document = MakeObject<Document>(_dataDir + u"DeleteImages.pdf");
// Delete a particular image
document->get_Pages()->idx_get(1)->get_Resources()->get_Images()->Delete(1);
// Save updated PDF file
document->Save(_dataDir + u"DeleteImages_out.pdf");
}