public void StartSplitter()
        {
            this.DialogResult = DialogResult.OK;

            int n = 1;

            foreach (PdfProjectElement ppe in this.Project.Elements)
            {
                if (!ppe.Enabled)
                {
                    continue;
                }
                if (ppe is PdfProjectPdf)
                {
                    foreach (int page in ((PdfProjectPdf)ppe).CalculatePageSelection(true))
                    {
                        using (Stream s = File.OpenRead(ppe.Path))
                        {
                            PdfParser parsed = PdfParser.Parse(s);
                            this.GenerateSplit(n, this.Project.Target, parsed, page);
                            n++;
                        }
                    }
                }
                if (ppe is PdfProjectImage)
                {
                    this.GenerateSplit(n, this.Project.Target, PdfParser.Parse(ImageToPDFConverter.ConvertImageToPDF(ppe.Path)), 0);
                    n++;
                }
            }
        }
Beispiel #2
0
 public override void AddToMerger(PdfMerger pdfMerger)
 {
     pdfMerger.Add(PdfParser.Parse(ImageToPDFConverter.ConvertImageToPDF(this.Path)));
 }
Beispiel #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("GIOS PDF Splitter and Merger - Version "
                              + Assembly.GetEntryAssembly().GetName().Version);
            Console.WriteLine("Copyright © 2009 Paolo Gios - www.paologios.com");
            Console.WriteLine();
            Console.WriteLine("Merges PDF and JPG files into a single PDF file.");
            Console.WriteLine();
            try
            {
                if (args.Length == 0)
                {
                    Help();
#if DEBUG
                    Console.ReadLine();
#endif
                    return;
                }

                string output = "";

                for (int index = 0; index < args.Length - 1; index++)
                {
                    string f = args[index].ToLower();
                    if (f == "output")
                    {
                        output = args[index + 1];
                        break;
                    }
                }

                if (output == null)
                {
                    return;
                }

                using (FileStream outputStream = new FileStream(output, FileMode.Create, FileAccess.Write))
                {
                    Stopwatch sw = new Stopwatch();
                    sw.Start();
                    Console.WriteLine("Creating " + output + " ...");
                    PdfMerger merger = new PdfMerger(outputStream);
                    merger.PdfMergerProgress += new EventHandler <PdfMergerProgressEventArgs>(merger_PdfMergerProgress);
                    for (int index = 0; index < args.Length; index++)
                    {
                        string f = args[index].ToLower();
                        if (f == "output")
                        {
                            index++;
                            continue;
                        }

                        string directory = Path.GetDirectoryName(f);

                        if (string.IsNullOrEmpty(directory))
                        {
                            directory = Environment.CurrentDirectory;
                        }

                        string[] files = Directory.GetFiles(directory, Path.GetFileName(f), SearchOption.TopDirectoryOnly);

                        Array.Sort(files);

                        foreach (string file in files)
                        {
                            if (string.Compare(file, outputStream.Name) == 0)
                            {
                                continue;
                            }

                            string extension = Path.GetExtension(file).ToLower();
                            Stream fs        = null;
                            switch (extension)
                            {
                            case ".pdf":
                                fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                                break;

                            case ".jpg":
                                fs = ImageToPDFConverter.ConvertImageToPDF(file);
                                break;

                            default:
                                continue;
                            }

                            using (fs)
                            {
                                Console.WriteLine();
                                Console.WriteLine("Adding " + file + "... ");
                                PdfParser pa = PdfParser.Parse(fs);
                                merger.Add(pa, null);
                                Console.SetCursorPosition(0, Console.CursorTop);
                                Console.WriteLine("Done.                                                    ");
                            }
                        }
                    }
                    Console.WriteLine();
                    Console.Write("Finishing ... ");
                    merger.Finish();
                    sw.Stop();
                    Console.WriteLine("Finished in " + sw.ElapsedMilliseconds + " ms.");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

#if DEBUG
            Console.ReadLine();
#endif
        }