Click here to Skip to main content
12,759,432 members (31,547 online)
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads

Stats

216.9K views
3.5K downloads
111 bookmarked
Posted 20 Dec 2005

GIOS PDF Splitter and Merger

, 28 Nov 2006 LGPL3
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...

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