Click here to Skip to main content
11,705,098 members (52,395 online)
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads
Add your own
alternative version

GIOS PDF Splitter and Merger

, 28 Nov 2006 LGPL3 188.4K 3K 110
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)

Share

About the Author

Paolo Gios
Web Developer
Italy Italy
Freelance software ASPNET / C# Software Developer

I live in Torino, Italy

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

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150819.1 | Last Updated 28 Nov 2006
Article Copyright 2005 by Paolo Gios
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid