Exemplo n.º 1
0
 public override void AddToMerger(PdfMerger pdfMerger)
 {
     using (Stream s = new FileStream(this.Path, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         PdfParser pa = PdfParser.Parse(s);
         pdfMerger.Add(pa, this.CalculatePageSelection(true));
     }
 }
		static void Main(string[] args)
		{
			string inputFile = args[0];
			string outputFile = args[1];
			int iterations = Int32.Parse(args[2]);

			// Merge the generated pdfs
			using (var outputStream = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
			{
				var merger = new PdfMerger(outputStream);
				for (int count = 1; count <= iterations; count++ )
				{
					using (var inputStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
					{
						var pdfParser = PdfParser.Parse(inputStream);
						merger.Add(pdfParser, null);
					}
				}

				merger.Finish();
			}
		}
		static void Main(string[] args)
		{
			string inputFile = args[0];
			string outputFile = args[1];
			int pageNumber = Int32.Parse(args[2]);

			string target = Path.Combine(Path.GetDirectoryName(outputFile),
				Path.GetFileNameWithoutExtension(outputFile) + " - " + pageNumber.ToString("00000") + ".pdf");

			using (var inputStream = new FileStream(inputFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
			{
				var pdfParser = PdfParser.Parse(inputStream);

				using (Stream s = new FileStream(target, FileMode.Create, FileAccess.Write))
				{
					var pdfMerger = new PdfMerger(s);
					pdfMerger = new PdfMerger(s);
					pdfMerger.Add(pdfParser, new int[] { pageNumber });
					pdfMerger.Finish();
				}
			}
		}
 public override void AddToMerger(PdfMerger pdfMerger)
 {
     using (Stream s = new FileStream(this.Path, FileMode.Open, FileAccess.Read, FileShare.Read))
     {
         PdfParser pa = PdfParser.Parse(s);
         pdfMerger.Add(pa, this.CalculatePageSelection(true));
     }
 }
 public override void AddToMerger(PdfMerger pdfMerger)
 {
     pdfMerger.Add(PdfParser.Parse(ImageToPDFConverter.ConvertImageToPDF(this.Path)));          
 }
Exemplo n.º 6
0
 public override void AddToMerger(PdfMerger pdfMerger)
 {
     pdfMerger.Add(PdfParser.Parse(ImageToPDFConverter.ConvertImageToPDF(this.Path)));
 }
Exemplo n.º 7
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
        }
        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
        }