示例#1
0
        /// <summary>
        /// Find PDF document Corruption
        /// </summary>
        /// <returns>Return the corrupted document result as string</returns>
        public string FindPDFCorruptionPDF()
        {
            //Initialize the instance of  FindPDFCorruptionMessage.
            FindPDFCorruptionMessage message = new FindPDFCorruptionMessage();
            FileStream pdfFile = new FileStream(ResolveApplicationPath("corrupted-document.pdf"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Create a new instance for the PDF analyzer.
            PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfFile);

            //Get the syntax errors.
            SyntaxAnalyzerResult result = analyzer.AnalyzeSyntax();

            //Check whether the document is corrupted or not.
            if (result.IsCorrupted)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("The PDF document is corrupted.");
                int count = 1;
                foreach (PdfException exception in result.Errors)
                {
                    builder.AppendLine(count++.ToString() + ": " + exception.Message);
                }
                message.Message = builder.ToString();
            }

            return(message.Message);
        }
        public ActionResult FindPDFCorruption(string FindCorruption)
        {
            string dataPath = _hostingEnvironment.WebRootPath + @"/PDF/";
            FindPDFCorruptionMessage message = new FindPDFCorruptionMessage();

            //Read the certificate file.
            FileStream pdfFile = new FileStream(dataPath + @"CorruptedDocument.pdf", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            //Create a new instance for the PDF analyzer.
            PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfFile);

            //Get the syntax errors.
            SyntaxAnalyzerResult result = analyzer.AnalyzeSyntax();

            //Check whether the document is corrupted or not.
            if (result.IsCorrupted)
            {
                StringBuilder builder = new StringBuilder();
                builder.AppendLine("The PDF document is corrupted.");
                int count = 1;
                foreach (PdfException exception in result.Errors)
                {
                    builder.AppendLine(count++.ToString() + ": " + exception.Message);
                }
                message.Message = builder.ToString();
            }

            return(View("FindPDFCorruption", message));
        }
        static void Main(string[] args)
        {
            //Load the PDF file as stream
            using (FileStream pdfStream = new FileStream(@"..\..\..\PDF-Files\input-open-repair.pdf", FileMode.Open, FileAccess.Read))
            {
                //Create a new instance of PDF document syntax analyzer.
                PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfStream);
                //Analyze the syntax and return the results
                SyntaxAnalyzerResult analyzerResult = analyzer.AnalyzeSyntax();

                //Check whether the document is corrupted or not
                if (analyzerResult.IsCorrupted)
                {
                    StringBuilder strBuilder = new StringBuilder();
                    strBuilder.AppendLine("The PDF document is corrupted.");
                    int count = 1;
                    foreach (PdfException exception in analyzerResult.Errors)
                    {
                        strBuilder.AppendLine(count++.ToString() + ": " + exception.Message);
                    }
                    Console.WriteLine(strBuilder);
                }
                else
                {
                    Console.WriteLine("No syntax error found in the provided PDF document");
                }
                analyzer.Close();
            }
        }
示例#4
0
        public ActionResult FindPDFCorruption(string InsideBrowser)
        {
            FindPDFCorruptionMessage message = new FindPDFCorruptionMessage();

            ////Create a new instance for the PDF analyzer.
            FileStream          fileStreamInput = new FileStream(ResolveApplicationDataPath("CorruptedDocument.pdf"), FileMode.Open, FileAccess.Read);
            PdfDocumentAnalyzer analyzer        = new PdfDocumentAnalyzer(fileStreamInput);
            StringBuilder       builder         = new StringBuilder();

            //Get the syntax errors.
            SyntaxAnalyzerResult result = analyzer.AnalyzeSyntax();

            //Check whether the document is corrupted or not.
            if (result.IsCorrupted)
            {
                builder.AppendLine("The PDF document is corrupted.");
                int count = 1;
                foreach (PdfException exception in result.Errors)
                {
                    builder.AppendLine(count++.ToString() + ": " + exception.Message);
                }
                message.Message = builder.ToString();
            }

            return(View("FindPDFCorruption", message));
        }
示例#5
0
        private static int TotalPageCount(string file)
        {
            try
            {
                if (file == @"C:\Users\PAB\Desktop\analitics\_Analytics\21132.pdf")
                {
                }
                using (StreamReader sr = new StreamReader(System.IO.File.OpenRead(file)))
                {
                    string line = "";
                    if (sr != null)
                    {
                        using (FileStream pdfStream = new FileStream(file, FileMode.Open, FileAccess.Read))
                        {
                            //Create a new instance of PDF document syntax analyzer.
                            PdfDocumentAnalyzer analyzer = new PdfDocumentAnalyzer(pdfStream);
                            //Analyze the syntax and return the results.
                            SyntaxAnalyzerResult analyzerResult = analyzer.AnalyzeSyntax();
                            if (analyzerResult.IsCorrupted == false && analyzerResult.Errors == null)
                            {
                                string ppath = file;
                                string text  = System.IO.File.ReadAllText(ppath);

                                PdfReader pdfReader     = new PdfReader(ppath);
                                int       numberOfPages = pdfReader.NumberOfPages;



                                Regex           regex   = new Regex(@"/Type\s*/Page[^s]");
                                MatchCollection matches = regex.Matches(sr.ReadToEnd());
                                return(numberOfPages);//matches.Count;
                            }
                            else
                            {
                                return(0);
                            }
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }