In This Topic
    Split a PDF document using a range of pages
    In This Topic

    Introduction

    The following example demonstrates how to split a PDF document into multiple documents, using a range of pages as division points.

    Split a PDF document
    Copy Code
    public static void SplitPdfByRangeOfPages()
    {
      Console.WriteLine( "=== SPLIT PDF BY RANGE OF PAGES ===" );
    
      var inputFile = "Animals.pdf";
    
      var outputFileName = "Animals.pdf";
      var outputPath = SplitPdfSample.SplitByRangeOfPagesOutputDirectory + outputFileName;
    
      // Load a Pdf Document.
      using( var document = PdfDocument.Load( SplitPdfSample.SplitPdfSampleResourceDirectory + inputFile ) )
      {
        // Split the loaded document in 3 and put the results in output path:
        // 1st part: pages 0 to 2.
        // 2nd part: pages 3 to 5.
        // 3rd part: pages 6 to 9.
        document.Split( SplitByPageOptions.ToPath( 0, 2, outputPath ) );
        document.Split( SplitByPageOptions.ToPath( 3, 5, outputPath ) );
        document.Split( SplitByPageOptions.ToPath( 6, 9, outputPath ) );
    
        Console.WriteLine( $"Info exported to folder: {SplitPdfSample.SplitByRangeOfPagesOutputDirectory}" );
      }
    }

    See Also