Ejemplo n.º 1
0
        public void ProcessTask(Options commandLineOptions)
        {
            String inputFile = commandLineOptions.Items[0];
            var    infoTools = new CoreTools();
            Dictionary <String, String> pdfInfo = new Dictionary <String, String>();

            try
            {
                if (commandLineOptions.showAll || commandLineOptions.showInfo)
                {
                    foreach (KeyValuePair <String, String> pdfInfoPair in infoTools.RetrieveBasicProperties(inputFile))
                    {
                        pdfInfo.Add(pdfInfoPair.Key, pdfInfoPair.Value);
                    }
                    foreach (KeyValuePair <String, String> pdfInfoPair in infoTools.RetrieveInfo(inputFile))
                    {
                        pdfInfo.Add(pdfInfoPair.Key, pdfInfoPair.Value);
                    }
                }
                if (commandLineOptions.showAll || commandLineOptions.showFields)
                {
                    foreach (KeyValuePair <String, String> pdfInfoPair in infoTools.RetrieveAcroFieldsData(inputFile))
                    {
                        pdfInfo.Add(pdfInfoPair.Key, pdfInfoPair.Value);
                    }
                }
                WriteResults(commandLineOptions.csvOutput, pdfInfo);
            }
            catch (ArgumentException argException)
            {
                // Output file prefix (-p) contains illegal characters.
                if (argException.Message.Contains("Illegal characters in path"))
                {
                    System.Console.Error.WriteLine(Environment.NewLine + argException.Message);
                }
            }
            catch (UnauthorizedAccessException)
            {
                System.Console.Error.WriteLine(Environment.NewLine + "Access denied.");
            }
            catch (System.IO.FileNotFoundException)
            {
                System.Console.Error.WriteLine(Environment.NewLine + "File not found.");
            }
            catch (IOException ioException)
            {
                // PDF file is not valid, or was not found
                if (ioException.Message.Contains("PDF"))
                {
                    System.Console.Error.WriteLine(Environment.NewLine + "Input file is not a valid PDF.");
                }
                else if (ioException.Message.Contains("not found as file or resource"))
                {
                    System.Console.Error.WriteLine(Environment.NewLine + ioException.Message);
                }
                else
                {
                    throw;
                }
            }
        }