6 Easy Ways to Split a PDF Document Using C# | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (175).NET Core  (29).NET MAUI  (208)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (220)BoldSign  (15)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (67)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (920)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (37)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (151)Chart  (132)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (633)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (41)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (508)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (597)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
6 Easy Ways to Split a PDF Document Using C#

6 Easy Ways to Split a PDF Document Using C#

Splitting a PDF document is a common use case in PDF document manipulation. It helps reduce the PDF file size by breaking down large documents into smaller pieces to send them via email or any other form of digital distribution.

With the help of the Syncfusion PDF Library, you can easily split large PDF documents, and you can also automate the split function for batch processing.

In this blog, we are going to explore the following six ways in which a PDF document can be split:

Let’s get started!

Say goodbye to tedious PDF tasks and hello to effortless document processing with Syncfusion's PDF Library.

#1: Split a PDF document into multiple files

The primary need of splitting a PDF document is to reduce the file size of the document. For example, if an organization generates reports containing the paychecks for all employees, then they need to split the entire PDF file into individual files and email them separately to the respective employees.

We can easily split each page in a PDF document into individual PDF documents with the following two steps:

  1. Load the PDF document.
  2. Call the Split function with an output file pattern.

The following code example shows how to split an existing PDF document.

//Load PDF document
PdfLoadedDocument document = new PdfLoadedDocument("PDF_Succinctly.pdf");
//Split PDF document with pattern
document.Split("Document-{0}.pdf");
//Close the document
document.Close(true);

By executing this code example, you will get individual PDF documents as shown in the following image.

Splitting a PDF document to multiple files
Splitting a PDF document to multiple files

#2: Split specific pages into a separate PDF document

With a large PDF document, there may be occasions where only a single page needs to be reviewed by someone. In that case, it would be very effective to send that particular page instead of the complete document.

The following code example shows how to split a particular page from an existing PDF document.

//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf");
//Create new PDF document
PdfDocument document = new PdfDocument();
//Import the particular page from the existing PDF
document.ImportPage(loadedDocument, 8);
//Save the new PDF document
document.Save("PDF_Succinctly8.pdf");
//Close the PDF document
document.Close(true);
loadedDocument.Close(true);

By executing this code, you will get a PDF document like the one in the following screenshot.

Splitting a specific page into a separate PDF
Splitting a specific page into a separate PDF

Explore the wide array of rich features in Syncfusion's PDF Library through step-by-step instructions and best practices.

#3: Split a range of pages into a separate PDF document

With the help of the Syncfusion PDF Library, you can split a range of pages from a large PDF document into an individual PDF. This will help the user send only the pages that need further processing, instead of sending the whole PDF document.

The following code example shows how to split a range of pages from an existing PDF document.

//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf");
//Create new PDF document
PdfDocument document = new PdfDocument();
//Import the range of pages from the existing PDF
document.ImportPageRange(loadedDocument, 2,8);
//Save the new PDF document
document.Save("PDF_Succinctly.pdf");
//Close the PDF document
document.Close(true);
loadedDocument.Close(true);

By executing this code, you will get a PDF document with multiple pages as shown in the following screenshot.

Splitting a range of pages into a separate PDF
Splitting a range of pages into a separate PDF

#4: Split a PDF document based on PDF bookmarks

A PDF document may contain bookmarks that indicate different sections. You can split a PDF document by sections using these bookmarks in cases where different sections of a PDF document should be reviewed by different people.

The following code example shows how to split a PDF document using a bookmark.

//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf");
PdfBookmarkBase bookmarks = loadedDocument.Bookmarks;
Dictionary<PdfPageBase, int> pages = new Dictionary<PdfPageBase, int>();
Dictionary<string, List<int>> splitRange = new Dictionary<string, List<int>>();

//Iterate all the pages and their indexes
for (int i = 0; i < loadedDocument.Pages.Count; i++)
{
  PdfPageBase page = loadedDocument.Pages[i] as PdfPageBase;
  pages.Add(page, i);
}

//Iterate all the bookmarks and their page ranges
for (int i = 0; i < bookmarks.Count; i++)
{
  if (bookmarks[i].Destination != null)
  {
    PdfPageBase page = bookmarks[i].Destination.Page;
    if (pages.ContainsKey(page))
    {
      //Bookmark doesn't have any child bookmark
      if (bookmarks[i].Count == 0)
      {
        int startIndex = pages[page];
        List<int> range = new List<int>();
        range.Add(startIndex);
        range.Add(startIndex);
        splitRange.Add(bookmarks[i].Title, range);
      }
      //Bookmark has child bookmark
      else
      {
        int startIndex = pages[page];
        int endIndex = startIndex;
        List<int> range = new List<int>();
        foreach (PdfLoadedBookmark bookmark in bookmarks[i])
        {
          PdfPageBase innerPage = bookmark.Destination.Page;
          if (pages.ContainsKey(innerPage))
          {
            endIndex = pages[innerPage];
          }
        }
        range.Add(startIndex);
        range.Add(endIndex);
        splitRange.Add(bookmarks[i].Title, range);
      }
    }
  }
}

//Split the PDF document based on the bookmark page range.
foreach (string title in splitRange.Keys)
{
  int startIndex = splitRange[title][0];
  int endIndex = splitRange[title][1];
  //Create a new PDF document.
  PdfDocument document = new PdfDocument();
  //Import the pages to the new PDF document.
  document.ImportPageRange(loadedDocument, startIndex, endIndex);
  //Save the document in a specified folder.
  document.Save(title + ".pdf");
  //Close the document.
  document.Close(true);
}
loadedDocument.Close(true);

On executing the code in this example, you will get individual PDF documents that each contain a different section of the original document, as shown in the following screenshot.

Splitting a PDF document based on PDF bookmarks
Splitting a PDF document based on PDF bookmarks

Witness the advanced capabilities of Syncfusion's PDF Library with feature showcases.

#5: Find a page with specific text and split it into a separate PDF

With the find text feature, you can split a particular page from a PDF based on the keyword present in the page. This will help you create a new document with the content you want.

The following code example shows how to split a PDF document using the find text feature.

//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf");
Dictionary<int, List<RectangleF>> textFound = new Dictionary<int, List<RectangleF>>();
//Find the text in the PDF document
loadedDocument.FindText("portable", out textFound);

PdfDocument document = new PdfDocument();

//Import page based on the find text index
foreach (int index in textFound.Keys)
{
  if (textFound[index].Count > 0)
  {
    document.ImportPage(loadedDocument, index);
  }
}

//Save the PDF document
document.Save("portable.pdf");
//Close the document
document.Close(true);
loadedDocument.Close(true);

In the above code example, we have searched for the text “portable” in the PDF. The text was found only in one page. That page has been split as a separate PDF file as shown in the following screenshot.

Find specific text in a page and split
Find specific text in a page and split

#6: Split a PDF into multiple documents with a specific number of pages:

You can split a large PDF document into multiple PDF files with any number of pages.

The following code sample shows how to split an existing PDF into multiple files with two pages each.

//Load the PDF document
PdfLoadedDocument loadedDocument = new PdfLoadedDocument("PDF_Succinctly.pdf");
//Split the PDF documents so that each contains only 2 pages
for (int i = 0; i < loadedDocument.Pages.Count; i = i + 2)
{
  //Create new PDF document
  PdfDocument document = new PdfDocument();
  //Import the particular page from the existing PDF
  document.ImportPageRange(loadedDocument, i,i+1);
  //Save the new PDF document
  document.Save("PDF_Succinctly-"+i+".pdf");
  //Close the PDF document
  document.Close(true);

}
loadedDocument.Close(true);

By executing the example, you will get a list of PDF documents with two pages each.

PDF Split into New Two-Page Document
PDF Split into New Two-Page Document

GitHub Sample

You can download all of these samples of splitting PDF documents on GitHub.

Syncfusion’s high-performance PDF Library allows you to create PDF documents from scratch without Adobe dependencies.

Conclusion

In this blog post, we learned six easy ways to split a PDF document using C#. I hope this blog post has been helpful to you. Splitting a PDF helps you reduce document file sizes and separate out your desired content. It also reduces the time spent on file transactions.

If you have any questions about these features, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

If you like this article, we think you will also like the following articles about the Syncfusion PDF Library:

Tags:

Share this post:

Comments (3)

Praveenkumar, the best!
Thanks Praveenkumar !

can we split one A4 into 2 pages A5 ?

Hi RICARDO,

At present, we do not have direct support for splitting the PDF document page into 2 pages in our PDF library. However, we can achieve your requirement by using PdfTemplate, we have created a sample to split the A4 document page into two A5 pages in a PDF document. We have attached the sample and output document for your reference, try the sample on your end and let us know whether it is suitable for you.

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/PdfSample-475580774
Document: https://www.syncfusion.com/downloads/support/directtrac/general/pd/TemplateOutput1-1397890039

You can refer to the below KB documentation link for more details,
KB: https://www.syncfusion.com/kb/9955/how-to-split-pdf-page-into-half-using-c-and-vb-net

Regards,
Chinnu M

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed