In This Topic
    Split a PDF document
    In This Topic

    Introduction

    The following example demonstrates how to split a PDF document using its pages as division points.

    Split a PDF document
    Copy Code
    public static void SplitPdfByPages()
    {
      Console.WriteLine( "=== SPLIT PDF BY PAGES ===" );
    
      var inputFile = "Animals.pdf";
    
      var outputFileName = "AnimalsByPages.pdf";
      var outputPath = SplitPdfSample.SplitByPagesOutputDirectory + 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 2.
        // 2nd part: pages 4.
        // 3rd part: pages 0.
        document.Split( SplitByPageOptions.ToPath( 2, outputPath ) );
        document.Split( SplitByPageOptions.ToPath( 4, outputPath ) );
        document.Split( SplitByPageOptions.ToPath( 0, outputPath ) );
    
        Console.WriteLine( $"Info exported to folder: {SplitPdfSample.SplitByPagesOutputDirectory}" );
      }
    }

    See Also