Используйте PdfReader.SelectPages () в сочетании с PdfStamper.Приведенный ниже код использует iTextSharp 5.5.1.
public void SelectPages(string inputPdf, string pageSelection, string outputPdf)
{
using (PdfReader reader = new PdfReader(inputPdf))
{
reader.SelectPages(pageSelection);
using (PdfStamper stamper = new PdfStamper(reader, File.Create(outputPdf)))
{
stamper.Close();
}
}
}
Затем этот метод вызывается с правильным выбором страницы для каждого условия.
Условие 1:
SelectPages(inputPdf, "1-4", outputPdf);
Условие 2:
SelectPages(inputPdf, "1-4,6", outputPdf);
или
SelectPages(inputPdf, "1-6,!5", outputPdf);
Условие 3:
SelectPages(inputPdf, "1-5", outputPdf);
Вот комментарий из исходного кода iTextSharp о том, что составляет выбор страницы.Это класс SequenceList, который используется для обработки выбора страницы:
/**
* This class expands a string into a list of numbers. The main use is to select a
* range of pages.
* <p>
* The general systax is:<br>
* [!][o][odd][e][even]start-end
* <p>
* You can have multiple ranges separated by commas ','. The '!' modifier removes the
* range from what is already selected. The range changes are incremental, that is,
* numbers are added or deleted as the range appears. The start or the end, but not both, can be ommited.
*/