Splits PDF document by pages

Namespace:  SautinSoft
Assembly:  PdfMetamorphosis (in PdfMetamorphosis.dll) Version: 7.1.2.14 (7.1.2.14)

Syntax

      
 C#  Visual Basic 
public int SplitPDFFileToPDFFolder(
	string SourceFile,
	string OutputPath
)
Public Function SplitPDFFileToPDFFolder ( _
	SourceFile As String, _
	OutputPath As String _
) As Integer

Parameters

SourceFile
String
Path to PDF file which you want to split by pages
OutputPath
String
Path to directory where to store each PDF page as single file after splitting

Return Value

0 - split successfully
2 - error, output directory doesn't exist

Remarks

Examples

CopyHow to split and merge PDF documents using C#
using System;
using System.IO;
using System.Collections;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            SautinSoft.PdfMetamorphosis p = new SautinSoft.PdfMetamorphosis();
            string rtfPath = @"..\..\..\..\Testing files\example.rtf";
            string pdfPath = @"..\..\..\..\Testing files\test.pdf";

            // Let's create a PDF file from RTF file
            p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape;

            //Specify page numbers: {1 of N}, font: Verdana, 18
            p.PageSettings.Numbering.Text = "{page} of {numpages}";
            p.PageSettings.Numbering.FontFace = "Verdana";
            p.PageSettings.Numbering.FontSize = 18;

            p.RtfToPdfConvertFile(rtfPath, pdfPath);

            #region split PDF file
            //Split PDF by pages: 1st, 2nd, 3rd ...
            p.SplitPDFFileToPDFFolder(pdfPath, Path.GetDirectoryName(pdfPath));
            #endregion

            #region merge PDF files
            //Merge only 1st and 3rd pages
            string[] pdfFiles = { @"..\..\..\..\Testing files\test-00001.pdf", @"..\..\..\..\Testing files\test-00003.pdf" };
            p.MergePDFFileArrayToPDFFile(pdfFiles, @"..\..\..\..\Testing files\test_Split_and_Merge_1and3page.pdf");
            #endregion

            //Show merged PDF (it doesn't have 2nd page)
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(@"..\..\..\..\Testing files\test_Split_and_Merge_1and3page.pdf") { UseShellExecute = true });
        }
    }
}
CopyHow to split and merge PDF documents using VB.Net
Imports System.IO

Module sample

    Sub Main()
        Dim p As New SautinSoft.PdfMetamorphosis()
        Dim rtfPath As String = "..\..\..\..\Testing files\example.rtf"
        Dim pdfPath As String = "..\..\..\..\Testing files\test.pdf"

        ' Let's create a PDF file from RTF file
        p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Landscape

        'Specify page numbers: {1 of N}, font: Verdana, 18
        p.PageSettings.Numbering.Text = "{page} of {numpages}"
        p.PageSettings.Numbering.FontFace = "Verdana"
        p.PageSettings.Numbering.FontSize = 18
        p.RtfToPdfConvertFile(rtfPath, pdfPath)

        'Split PDF by pages: 1st, 2nd, 3rd ...
        p.SplitPDFFileToPDFFolder(pdfPath, Path.GetDirectoryName(pdfPath))

        'Merge only 1st and 3rd pages
        Dim pdfFiles() As String = {"..\..\..\..\Testing files\test-00001.pdf", "..\..\..\..\Testing files\test-00003.pdf"}
        p.MergePDFFileArrayToPDFFile(pdfFiles, "..\..\..\..\Testing files\test_Split_and_Merge_1and3page.pdf")

        'Show merged PDF (it doesn't have 2nd page)
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo("..\..\..\..\Testing files\test_Split_and_Merge_1and3page.pdf") With {.UseShellExecute = True})

    End Sub
End Module

See Also