Ejemplo n.º 1
0
        private static void StitchPdf(StitcherBuilder stitcherBuilder, out PdfDocument document)
        {
            document = new PdfDocument();

            if ((stitcherBuilder.Files == null || stitcherBuilder.Files.Count() == 0) && stitcherBuilder.Pattern == null) //Get all pdfs in origin directory.
            {
                string[] files = Directory.GetFiles(stitcherBuilder.Origin + "\\", "*.pdf", (stitcherBuilder.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));

                StitchDocuments(files, stitcherBuilder.Rotation, ref document);
            }
            else if (stitcherBuilder.Pattern != null) //Use the regex string to get all needed files
            {
                string        fileName;
                string[]      files        = Directory.GetFiles(stitcherBuilder.Origin + "\\", "*.pdf", (stitcherBuilder.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
                List <string> matchedFiles = new List <string>();
                foreach (string file in files)
                {
                    int startIndex = file.LastIndexOf('\\') + 1;
                    int length     = file.Length - startIndex - 4;
                    fileName = file.Substring(startIndex, length);

                    if (Regex.IsMatch(fileName, stitcherBuilder.Pattern))
                    {
                        matchedFiles.Add(stitcherBuilder.Origin + "\\" + fileName + ".pdf");
                    }
                }

                StitchDocuments(matchedFiles, stitcherBuilder.Rotation, ref document);
            }
            else //Use the file list
            {
                //StitchDocuments(stitcherBuilder.Files.Select(s => string.Concat(stitcherBuilder.Origin + "\\" + (s.First() == '\"' ? s.Substring(1, s.Length - 2) : s) + ".pdf")), stitcherBuilder.Rotation, ref document);
                StitchDocuments(stitcherBuilder.Files.Select(s => string.Concat((File.Exists(stitcherBuilder.Origin + "\\" + (s.First() == '\"' ? s.Substring(1, s.Length - 2) : s) + ".pdf") ? (stitcherBuilder.Origin + "\\" + (s.First() == '\"' ? s.Substring(1, s.Length - 2) : s) + ".pdf") : (s.First() == '\"' ? s.Substring(1, s.Length - 2) : s)))), stitcherBuilder.Rotation, ref document);
            }
        }
Ejemplo n.º 2
0
        internal StitcherGUI(StitcherBuilder stitcherBuilder)
        {
            InitializeComponent();

            this.stitcherBuilder = stitcherBuilder;
            loaded = false;
        }
Ejemplo n.º 3
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("No parameters supplied; type 'help' for the list of switches.");
                return;
            }
            if (args[0].ToLower() == "help")
            {
                Console.WriteLine("-g=? Use GUI mode. (Default is false)");
                Console.WriteLine("-r=? Degrees of rotation to be applied to documents: must be a multiple of 90. (Default 0)");
                Console.WriteLine("-o=? Origin directory to search. (Default is current directory)");
                Console.WriteLine("-c=? Search sub folders within origin directory? (Default true)");
                Console.WriteLine("-d=? Destination directory for output pdf. (Default if current directory)");
                Console.WriteLine("-n=? Name of merged file. (Default is 'MERGED_DATETIME')");
                Console.WriteLine("-f={?} Files to be merged seperated by a colon ':'. (Default is all documents of selected type in orgin directory)");
                Console.WriteLine("-x=? Regex string to be parsed to get files to merge. (Takes priority over a list of files)");
                Console.WriteLine("-s=? Show the PDF after creation. (Default is true)");
                return;
            }
            else
            {
                StitcherBuilder stitcherBuilder = new StitcherBuilder();
                foreach (string argument in args)
                {
                    switch (argument[1])
                    {
                    case 'g':
                        UseGuiMode = bool.Parse(argument.Substring(3));
                        break;

                    case 'r':
                        stitcherBuilder.Rotation = int.Parse(argument.Substring(3));
                        break;

                    case 'o':
                        stitcherBuilder.Origin = argument.Substring(3);
                        break;

                    case 'c':
                        stitcherBuilder.Recursive = bool.Parse(argument.Substring(3));
                        break;

                    case 'd':
                        stitcherBuilder.Destination = argument.Substring(3);
                        break;

                    case 'n':
                        stitcherBuilder.Name = argument.Substring(3);
                        break;

                    case 'f':
                        string fileStr = argument.Substring(4);
                        stitcherBuilder.Files = fileStr.Remove(fileStr.Length - 1, 1).Split(':');
                        break;

                    case 'x':
                        stitcherBuilder.Pattern = argument.Substring(3);
                        break;

                    case 's':
                        stitcherBuilder.Show = bool.Parse(argument.Substring(3));
                        break;

                    default:
                        break;
                    }
                }

                if (UseGuiMode)
                {
                    stitcherBuilder.Canceled = true;
                    System.Threading.Thread gui = new System.Threading.Thread(() => { Application.Run(new StitcherGUI(stitcherBuilder)); });
                    gui.SetApartmentState(System.Threading.ApartmentState.STA);
                    gui.Start();
                    gui.Join();
                }

                if (stitcherBuilder.IsValid && !stitcherBuilder.Canceled)
                {
                    PdfDocument pdfDocument = stitcherBuilder.Stitch();
                    if (pdfDocument == null)
                    {
                        Console.WriteLine("Returned a null document.");
                        return;
                    }

                    pdfDocument.Save(@stitcherBuilder.Destination + "\\" + stitcherBuilder.Name + ".pdf");
                    Console.WriteLine("\r\nPDF Created");

                    if (stitcherBuilder.Show)
                    {
                        try
                        {
                            Process.Start(@stitcherBuilder.Destination + "\\" + stitcherBuilder.Name + ".pdf");
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Can not complete operation; Type or Name switch is invalid.");
                }
            }
        }
Ejemplo n.º 4
0
 private static void StitchInventor(StitcherBuilder stitcherBuilder, out PdfDocument document)
 {
     document = new PdfDocument();
 }
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("No parameters supplied; type 'help' for the list of switches.");
                return;
            }
            if (args[0].ToLower() == "help")
            {
                Console.WriteLine("-t=? Type of document to stitch (Arguments: pdf/inventor)");
                Console.WriteLine("-r=? Degrees of rotation to be applied to documents: must be a multiple of 90 (Default 0)");
                Console.WriteLine("-o=? Origin directory to search (Default is current directory)");
                Console.WriteLine("-c=? Search sub folders within origin directory? (Default true)");
                Console.WriteLine("-d=? Destination directory for output pdf (Default if current directory)");
                Console.WriteLine("-n=? Name of merged file (Default is 'MERGED_DATETIME')");
                Console.WriteLine("-f={?} Files to be merged seperated by a colon ':' (Default is all documents of selected type in orgin directory)");
                Console.WriteLine("-x=? Regex string to be parsed to get files to merge. (Takes priority over a list of files)");
                Console.WriteLine("-s=? Show the PDF after creation. (Default true)");
                return;
            }
            else
            {
                StitcherBuilder stitcherBuilder = new StitcherBuilder();
                foreach (string argument in args)
                {
                    switch (argument[1])
                    {
                    case 't':
                        stitcherBuilder.Type = StitcherBuilder.GetType(argument.Substring(3));
                        break;

                    case 'r':
                        stitcherBuilder.Rotation = int.Parse(argument.Substring(3));
                        break;

                    case 'o':
                        stitcherBuilder.Origin = argument.Substring(3);
                        break;

                    case 'c':
                        stitcherBuilder.Recursive = bool.Parse(argument.Substring(3));
                        break;

                    case 'd':
                        stitcherBuilder.Destination = argument.Substring(3);
                        break;

                    case 'n':
                        stitcherBuilder.Name = argument.Substring(3);
                        break;

                    case 'f':
                        string fileStr = argument.Substring(4);
                        stitcherBuilder.Files = fileStr.Remove(fileStr.Length - 1, 1).Split(':');
                        break;

                    case 'x':
                        stitcherBuilder.Pattern = argument.Substring(3);
                        break;

                    case 's':
                        stitcherBuilder.Show = bool.Parse(argument.Substring(3));
                        break;

                    default:
                        break;
                    }
                }

                if (stitcherBuilder.IsValid)
                {
                    PdfDocument pdfDocument = stitcherBuilder.Stitch();
                    if (pdfDocument == null)
                    {
                        Console.WriteLine("Returned a null document.");
                        return;
                    }

                    pdfDocument.Save(@stitcherBuilder.Destination + "\\" + stitcherBuilder.Name + ".pdf");
                    Console.WriteLine("\r\nPDF Created");

                    if (stitcherBuilder.Show)
                    {
                        try
                        {
                            Process.Start("acrobat", @stitcherBuilder.Destination + "\\" + stitcherBuilder.Name + ".pdf");
                        }
                        catch (Exception)
                        {
                            try
                            {
                                Process.Start("AcroRd32", @stitcherBuilder.Destination + "\\" + stitcherBuilder.Name + ".pdf");
                            }
                            catch (Exception)
                            {
                                try
                                {
                                    Process.Start(@stitcherBuilder.Destination + "\\" + stitcherBuilder.Name + ".pdf");
                                }
                                catch (Exception)
                                {
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Can not complete operation; Type or Name switch is invalid.");
                }
            }
        }