Click here to Skip to main content
15,878,959 members
Articles / Desktop Programming / Windows Forms

GIOS PDF Splitter and Merger

Rate me:
Please Sign up or sign in to vote.
4.92/5 (45 votes)
28 Nov 2006LGPL34 min read 936.4K   4.1K   111  
The first open source PDF splitter and merger tool written in C#.
using System;
using System.IO;
using System.Collections;
using System.Windows.Forms;
using System.Text.RegularExpressions;

namespace Gios.Pdf.SplitMerge
{
    public class ProjectPart
	{
		private void OnProgress(int part, int total){}		
		internal event ProgressDelegate ProgressEvent;
		public string path;
		internal string pages;
        public int[] Pages
        {
            get
            {
                ArrayList ps = new ArrayList();
                if (this.pages == null || pages.Length == 0)
                {
                    for (int index = 0; index < this.MaxPage; index++)
                    {
                        ps.Add(index);
                    }
                }
                else
                {
                    string[] ss = this.pages.Split(new char[] { ',',' ',';' });
                    foreach (string s in ss)
                        if (Regex.IsMatch(s, @"\d+-\d+"))
                        {
                            int start = int.Parse(s.Split(new char[] { '-' })[0]);
                            int end = int.Parse(s.Split(new char[] { '-' })[1]);
                            if (start > end)
                                return new int[] {0 };
                            while (start <= end)
                            {
                                ps.Add(start-1);
                                start++;
                            }
                        }
                        else
                        {
                            ps.Add(int.Parse(s)-1);
                        }
                }
                return ps.ToArray(typeof(int)) as int[];
            }           
        }
		public int MaxPage;
       public void Load(string path)
		{
			this.path=path;
			PdfFile pf=new PdfFile(File.OpenRead(path));
			pf.ProgressEvent+=new ProgressDelegate(pf_ProgressEvent);
			pf.Load();
			this.MaxPage=pf.PageCount;
		}
		public ProjectPart()
		{
			this.ProgressEvent=new ProgressDelegate(this.OnProgress);			
		}
		public ListViewItem ListViewItem
		{
			get
			{
				ListViewItem lvi = new ListViewItem(new string[] {this.pages, this.MaxPage.ToString(), this.path });
				lvi.Tag=this;                
				return lvi;
			}
		}
		

		private void pf_ProgressEvent(int part, int total)
		{
			this.ProgressEvent(part,total);
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)


Written By
Web Developer
Italy Italy
Freelance software ASPNET / C# Software Developer

I live in Torino, Italy

my homepage is: http://www.paologios.com

Comments and Discussions