Delete PDF pages in C++
Contents
[
Hide
]
Remove one page or a selected set of pages from a PDF document using Aspose.PDF for C++.
Delete a single page
The input PDF must contain page 2.
- Open the input PDF as a Document.
- Call Delete() on PageCollection for page 2.
- Save the result with Save().
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
using namespace System;
using namespace Aspose::Pdf;
// Port of DeletePagesExamples.deletePage.
void DeletePage(System::String inputFile, System::String outputFile)
{
auto document = MakeObject<Document>(inputFile);
document->get_Pages()->Delete(2);
document->Save(outputFile);
}
Delete multiple pages
The input PDF must contain at least four pages.
- Open the input PDF as a Document.
- Create an array containing page numbers 2, 3, and 4.
- Pass the array to Delete() on PageCollection.
- Save the result with Save().
#include <system/array.h>
#include <Aspose.PDF.Cpp/Document.h>
#include <Aspose.PDF.Cpp/Page.h>
#include <Aspose.PDF.Cpp/PageCollection.h>
using namespace System;
using namespace Aspose::Pdf;
// Port of DeletePagesExamples.deleteBunchPages.
void DeleteBunchPages(System::String inputFile, System::String outputFile)
{
auto document = MakeObject<Document>(inputFile);
document->get_Pages()->Delete(MakeArray<int32_t>({2, 3, 4}));
document->Save(outputFile);
}