What you want to see on DotNetFunda.com ?
DotNetFunda.Com Logo
Twitter TwitterLinkedIn
YouTubeGoogle
 Online : 14364 |  Welcome, Guest!   Register  Login
 Home > Blogs > C# > Split One PDF Document to Multiple Files with C#, VB.NET ...
Lacy

Split One PDF Document to Multiple Files with C#, VB.NET

 Blog author: Lacy | Posted on: 5/27/2012 | Category: C# Blogs | Views: 1562 | Status: [Member] | Points: 75 | Alert Moderator   


PDF Split function allows users to divide one PDF Document to multiple files. It is much like that when we read a book, but we do not necessary to read them all, so we select the chapters that we need to read. When we do this, we actually unconsciously split the book into two or more books. PDF Split function enables people to split the information according to the category and provides great convenience to find the certain information in a short time. 

Now, let us look at the top of this website. The different categories in the top split the whole website into multiple kinds, which is very convenient. That is why we split one PDF Document to multiple files.

This task needs a document of at least two pages. I use a PDF creation component Spire.PDF which contains a PDF Document of eight pages and can split PDF document with a fast speed.


Procedure:

1.Load the PDF Document "Sample3.pdf" from Spire.PDF in the system.

2.Split the PDF Document to multiple files. In the code, I split the eight pages' PDF Document to eight PDF files.

3.Launch the project and see the eight PDF files.


Main Code:
C# Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spire.Pdf;
namespace split_pdf
{
    class Program
    {
        static void Main(string[] args)
        {
            //open pdf document
           PdfDocument doc = new PdfDocument(@"C:\Program
 Files\e-iceblue\Spire.Pdf\Demos\Data\Sample3.pdf");
            //Split the PDF Document
            String pattern = "SplitDocument-{0}.pdf";
            doc.Split(pattern);
            String lastPageFileName
                = String.Format(pattern, doc.Pages.Count - 1);
            doc.Close();
            //Launching the Pdf file.
            System.Diagnostics.Process.Start(lastPageFileName);
        }
    }
}

VB.NET Code:
Imports System;
Imports System.Collections.Generic;
Imports System.Linq;
Imports System.Text;
Imports Spire.Pdf;
Namespace split_pdf
    Friend Class Program
        Shared Sub Main(ByVal args() As String)
            'open pdf document
            Dim doc As New PdfDocument("C:\Program Files\e-iceblue\Spire.Pdf\Demos\Data\Sample3.pdf")
            'Split the PDF Document
            Dim pattern As String = "SplitDocument-{0}.pdf"
            doc.Split(pattern)
            Dim lastPageFileName As String = String.Format(pattern, doc.Pages.Count - 1)
            doc.Close()
            'Launching the Pdf file.
            Process.Start(lastPageFileName)
        End Sub
    End Class
End Namespace


We can choose Document 5 to preview:
                              

Obviously, using Spire.PDF for .NET, we can easily split one PDF Document to multiple PDF files. Besides, Spire.PDF has many other rich functions, such as embedding fonts, draw shapes, load images to PDF Document, import data, Auto Page Breaks for large tables and so on.




Found interesting? Add this to:


About Keating Arly

Experience:1 year(s)
Home page:http://www.e-iceblue.com
Member since:Tuesday, March 27, 2012
Level:Starter
Status: [Member]
Biography:
>> Write Response - Respond to this post and get points

More Blogs

About Us | Contact Us | The Team | Advertise | Software Development | Write for us | Testimonials | Privacy Policy | Terms of Use | Link Exchange | Members | Go Top
General Notice: If you find plagiarised (copied) contents on this page, please let us know the original source along with your correct email id (to communicate) for further action.
Copyright © DotNetFunda.Com. All Rights Reserved. Copying or mimicking the site design and layout is prohibited. Logos, company names used here if any are only for reference purposes and they may be respective owner's right or trademarks. | 5/21/2013 5:03:49 AM