Splits PDF document by pages

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


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


Path to PDF file which you want to split by pages
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



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 = @"..\..\..\..\..\test.rtf";
            string pdfPath = @"..\..\..\..\..\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 and 3rd
            p.SplitPDFFileToPDFFolder(pdfPath, Path.GetDirectoryName(pdfPath));

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

            //Show merged PDF (it doesn't have 2nd page)
CopyHow to split and merge PDF documents using VB.Net
Imports System
Imports System.IO
Imports System.Text

Module sample

    Sub Main()
        Dim p As New SautinSoft.PdfMetamorphosis()
        'After purchasing the license, please insert your serial number here to activate the component
        'p.Serial = "XXXXXXXXXXX";

        'specify some options
        p.PageSettings.Orientation = SautinSoft.PdfMetamorphosis.PageSetting.Orientations.Auto
        p.PageSettings.Numbering.Text = "Page {page} of {numpages}"

        If p IsNot Nothing Then
            Dim inputFile As String = "..\..\..\..\..\test.htm"
            Dim outputFile As String = "..\..\..\..\..\test.pdf"

            Dim result As Integer = p.HtmlToPdfConvertFile(inputFile, outputFile)

            If result = 0 Then
                System.Console.WriteLine("Converted successfully!")
                System.Console.WriteLine("Converting Error!")
            End If
        End If
    End Sub
End Module

See Also