예제 #1
0
        public string PdfFields()
        {
            string    pdfText = String.Empty;
            PDFParser parser  = new PDFParser(new BufferedInputStream(new FileInputStream(PdfFile)));

            parser.parse();
            PDDocument originialPdfDoc = parser.getPDDocument();

            bool isOriginalDocEncrypted = originialPdfDoc.isEncrypted();

            if (isOriginalDocEncrypted)
            {
                originialPdfDoc.openProtection(new StandardDecryptionMaterial(PdfPassword));
            }

            try
            {
                PDDocumentCatalog docCatalog = originialPdfDoc.getDocumentCatalog();
                PDAcroForm        acroForm   = docCatalog.getAcroForm();
                PDField           field      = acroForm.getField("Name");
                if (field != null)
                {
                    field.setValue("name");
                }
            }
            catch (java.io.IOException ex)
            {
                throw ex;
            }
            return(pdfText);
        }
예제 #2
0
        public string PdfToText()
        {
            string    pdfText = String.Empty;
            PDFParser parser  = new PDFParser(new BufferedInputStream(new FileInputStream(PdfFile)));

            parser.parse();
            PDDocument originialPdfDoc = parser.getPDDocument();

            bool isOriginalDocEncrypted = originialPdfDoc.isEncrypted();

            if (isOriginalDocEncrypted)
            {
                originialPdfDoc.openProtection(new StandardDecryptionMaterial(PdfPassword));
            }
            PDFTextStripper stripper = new PDFTextStripper();

            try
            {
                pdfText = stripper.getText(originialPdfDoc);
            }
            catch (java.io.IOException ex)
            {
                throw ex;
            }
            return(pdfText);
        }
예제 #3
0
        //Conversão do PDF
        public void ReadPDF()
        {
            IWebDriver driver = new ChromeDriver();

            URL TestURL = new URL(driver.Url);

            BufferedInputStream TestFile = new BufferedInputStream(TestURL.openStream());
            PDFParser           TestPDF  = new PDFParser(TestFile);

            TestPDF.parse();
            String TestText = new PDFTextStripper().getText(TestPDF.getPDDocument());

            System.IO.File.WriteAllText(@"C:\Users\Nicolas PC\Desktop\teste\PDFTESTE.txt", TestText);
        }
예제 #4
0
        public void Infocrim()
        {
            var options = new ChromeOptions();

            options.AddArguments("headless");
            //using (IWebDriver driver = new ChromeDriver("C:/inetpub/wwwroot/wwwroot",options))
            using (IWebDriver driver = new ChromeDriver())
            {
                Actions builder = new Actions(driver);

                //Validação
                driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/ ");
                driver.FindElement(By.Id("username")).SendKeys("fiap");
                driver.FindElement(By.Id("password")).SendKeys("mpsp");
                driver.FindElement(By.Id("password")).SendKeys(Keys.Enter);

                driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/infocrim/login.html");
                driver.FindElement(By.XPath("/html/body/table/tbody/tr[3]/td/table/tbody/tr/td/table/tbody/tr/td/table/tbody/tr[2]/td[4]/a/img")).Click();
                driver.FindElement(By.XPath("/html/body/a/table[3]/tbody/tr/td[2]/table[1]/tbody/tr[3]/td/table/tbody/tr[2]/td/table/tbody/tr/td/div/a/img")).Click();
                driver.FindElement(By.XPath("/html/body/table/tbody/tr[2]/td/table[3]/tbody/tr[2]/td[2]/a")).Click();
                driver.FindElement(By.XPath("/html/body/table/tbody/tr/td/a[2]/img")).Click();
                driver.FindElement(By.XPath("/html/body/print-preview-app//print-preview-sidebar//div[2]/print-preview-destination-settings//print-preview-settings-section[1]/div/print-preview-destination-select//select")).Click();
                driver.FindElement(By.XPath("/html/body/print-preview-app//print-preview-sidebar//div[2]/print-preview-destination-settings//print-preview-settings-section[1]/div/print-preview-destination-select//select/option[2]")).Click();

                URL url = new URL(driver.Url);
                BufferedInputStream fileToParse = new BufferedInputStream(url.openStream());
                PDFParser           parser      = new PDFParser(fileToParse);
                parser.parse();
                COSDocument     cosDoc      = parser.getDocument();
                PDDocument      pdDoc       = new PDDocument(cosDoc);
                PDFTextStripper pdfStripper = new PDFTextStripper();
                pdfStripper.setStartPage(1);
                pdfStripper.setEndPage(1);
                string parsedText = pdfStripper.getText(cosDoc);

                string saida = new PDFTextStripper().getText(parser.getPDDocument());

                System.IO.File.WriteAllText(@"C:\Users\favar\Desktop\Texto\Infocrim.txt", saida);
            }
        }
        public string Parse(string fileName)
        {
            //Load in file. Using java.io because pdfbox is ported from java.
            var pdfFile = new FileInputStream(fileName);

            //Load file into the pdf parser
            var pdfParser = new PDFParser(pdfFile);

            //Parse the document, so that we can get it for the COSDocument
            pdfParser.parse();

            /*
            COSDocument is the in-memory representation of the PDF.
            see https://pdfbox.apache.org/docs/1.8.4/javadocs/org/apache/pdfbox/cos/COSDocument.html
            */
            var cosDocument = pdfParser.getDocument();

            var pdDocument = new PDDocument(cosDocument);

            //Instantiate text stripper.
            var pdfTextStripper = new PDFTextStripper();

            /* Needed for only stripping specific pages

            pdfTextStripper.setStartPage(0);
            pdfTextStripper.setEndPage(pdDocument.getNumberOfPages());

            */

            //Needed so that we can close the pdDocument before returning from this method
            var strippedText = pdfTextStripper.getText(pdDocument);

            //This closes all storage and delete the tmp files.
            pdDocument.close();
            cosDocument.close();

            return strippedText;
        }
예제 #6
0
        public string Detran(PesquisaCPFCNPJ pesquisaCPFCNPJ)
        {
            var options = new ChromeOptions();

            //options.AddArguments("headless");
            options.AddArguments("no-sandbox");
            using (IWebDriver driver = new ChromeDriver("C:/inetpub/wwwroot/wwwroot", options))
            //using (IWebDriver driver = new ChromeDriver(options))
            {
                Actions builder = new Actions(driver);

                driver.Navigate().GoToUrl("http://ec2-18-231-116-58.sa-east-1.compute.amazonaws.com/detran/login.html");
                driver.FindElement(By.Id("form:j_id563205015_44efc15b")).Click();
                driver.FindElement(By.Id("navigation_a_M_16")).Click();
                driver.FindElement(By.XPath("//*[@id='navigation_a_F_16']")).Click();
                driver.FindElement(By.Id("form:rg")).SendKeys(pesquisaCPFCNPJ.CPFCNPJ.ToString());
                driver.FindElement(By.Id("form:nome")).SendKeys(pesquisaCPFCNPJ.Nome);
                driver.FindElement(By.LinkText("Pesquisar")).Click();

                driver.SwitchTo().Window(driver.WindowHandles[1]);
                URL url = new URL(driver.Url);
                BufferedInputStream fileToParse = new BufferedInputStream(url.openStream());
                PDFParser           parser      = new PDFParser(fileToParse);
                parser.parse();
                COSDocument     cosDoc      = parser.getDocument();
                PDDocument      pdDoc       = new PDDocument(cosDoc);
                PDFTextStripper pdfStripper = new PDFTextStripper();
                pdfStripper.setStartPage(1);
                pdfStripper.setEndPage(1);
                string parsedText = pdfStripper.getText(pdDoc);

                string saida = new PDFTextStripper().getText(parser.getPDDocument());

                driver.SwitchTo().Window(driver.WindowHandles[0]);
                driver.FindElement(By.Id("navigation_a_M_16")).Click();
                driver.FindElement(By.PartialLinkText("Consultar Imagem da CNH")).Click();
                driver.FindElement(By.LinkText("Pesquisar")).Click();
                driver.SwitchTo().Window(driver.WindowHandles[2]);
                //string nomePai = driver.FindElement(By.XPath("/html/body/div[4]/div/table/tbody/tr/td/div/div/form/div[3]/div/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]")).Text;
                string nPai = driver.FindElement(By.XPath("/html/body/div[4]/div/table/tbody/tr/td/div/div/form/div[3]/div/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[3]/td/table/tbody/tr[2]/td/span")).Text;
                string nMae = driver.FindElement(By.XPath("/html/body/div[4]/div/table/tbody/tr/td/div/div/form/div[3]/div/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr[2]/td/span")).Text;


                driver.SwitchTo().Window(driver.WindowHandles[0]);
                driver.FindElement(By.Id("navigation_a_M_18")).Click();
                driver.FindElement(By.PartialLinkText("Consultar Veículo Base Estadual")).Click();
                driver.FindElement(By.XPath("/html/body/div[4]/div/table/tbody/tr/td/div/div/form/div[1]/div[2]/table[2]/tbody/tr[2]/td[2]/input")).SendKeys(pesquisaCPFCNPJ.CPFCNPJ.ToString());
                driver.FindElement(By.LinkText("Pesquisar")).Click();
                driver.SwitchTo().Window(driver.WindowHandles[3]);

                URL urlCarro = new URL(driver.Url);
                BufferedInputStream fileToParseCarro = new BufferedInputStream(urlCarro.openStream());
                PDFParser           parserCarro      = new PDFParser(fileToParseCarro);
                parserCarro.parse();
                COSDocument     cosDocCarro      = parserCarro.getDocument();
                PDDocument      pdDocCarro       = new PDDocument(cosDocCarro);
                PDFTextStripper pdfStripperCarro = new PDFTextStripper();
                pdfStripper.setStartPage(1);
                pdfStripper.setEndPage(1);
                string parsedTextCarro = pdfStripperCarro.getText(pdDocCarro);

                string saidaCarro = new PDFTextStripper().getText(parserCarro.getPDDocument());

                string resultado = saida + nPai + nMae + saidaCarro;

                string[] strsplit = resultado.Replace("\r\n", ":").Split(':');

                string cpf               = strsplit[33].Trim();
                string rg                = strsplit[13].Trim();
                string expeditor         = strsplit[34].Trim();
                string registro          = strsplit[36].Trim();
                string local             = strsplit[38].Trim();
                string espelhoPid        = strsplit[40].Trim();
                string emissaoCnh        = strsplit[42].Trim();
                string categoria         = strsplit[46].Trim();
                string primeiraHab       = strsplit[48].Trim();
                string statusCnh         = strsplit[50].Trim();
                string renach            = strsplit[52].Trim();
                string espelhoCnh        = strsplit[54].Trim();
                string validadeCnh       = strsplit[56].Trim();
                string pontuacao         = strsplit[58].Trim();
                string nomePai           = strsplit[119].Trim();
                string nomeMae           = strsplit[120].Trim();
                string placa             = strsplit[144].Replace(" 7107 - SAO PAULO", "").Trim();
                string municipioPlaca    = strsplit[144].Replace("gge4223  ", "").Trim();
                string renavam           = strsplit[146].Replace("  9AAAAVAU0J4001600 ", "").Trim();
                string chassi            = strsplit[146].Replace("01172566666  ", "").Trim();
                string numMotor          = strsplit[148].Replace("  22/11/18 00", "").Trim();
                string dataAltMotor      = strsplit[148].Replace("CWL031481  ", "").Trim();
                string tipo              = strsplit[151].Replace(" 1 - IMPORTADO 16 - ALCO/GASOL", "").Trim();
                string procedencia       = strsplit[151].Replace("6 - AUTOMOVEL ", "").Replace(" 16 - ALCO/GASOL ", "").Trim();
                string combustivel       = strsplit[151].Replace("6 - AUTOMOVEL 1 - IMPORTADO ", "").Trim();
                string cor               = strsplit[153].Replace("  162801 – VARIANT GL ", "").Trim();
                string marcaModelo       = strsplit[153].Replace("4 - BRANCA  162801 – ", "").Trim();
                string categoriaAut      = strsplit[155].Replace(" 1971 1972 ", "").Trim();
                string anoFab            = strsplit[155].Replace("1 - PARTICULAR ", "").Replace(" 1972 ", "").Trim();
                string anoMod            = strsplit[155].Replace("1 - PARTICULAR 1971 ", "").Trim();
                string logradouro        = strsplit[166].Replace("  00121 ", "").Trim();
                string numero            = strsplit[166].Replace("AV LINS DE VASCONCELOS  ", "").Trim();
                string complemento       = strsplit[182].Replace("  010006-010 ", "").Trim();
                string cep               = strsplit[182].Replace("4 ANDAR  ", "").Trim();
                string bairro            = strsplit[184].Replace(" 7107 - SAO PAULO SP ", "").Trim();
                string licenciamento     = strsplit[225].Replace("   07/03/2019 ", "").Trim();
                string dataLicenciamento = strsplit[225].Replace("2019   ", "").Trim();
                string dataEmissaoCRV    = strsplit[227].Trim();

                DetranModel objDen = new DetranModel();
                objDen.CNPJCPF             = long.Parse(cpf.Replace(".", "").Replace("-", ""));
                objDen.RG                  = rg;
                objDen.Expeditor           = expeditor;
                objDen.Registro            = registro;
                objDen.Local               = local;
                objDen.PID                 = espelhoPid;
                objDen.EmissaoCnh          = emissaoCnh;
                objDen.Categoria           = categoria;
                objDen.PrimeiraHabilitação = primeiraHab;
                objDen.StatusCnh           = statusCnh;
                objDen.Renach              = renach;
                objDen.EspelhoCnh          = espelhoCnh;
                objDen.ValidadeCnh         = validadeCnh;
                objDen.Pontuacao           = pontuacao;
                objDen.NomePai             = nPai;
                objDen.NomeMae             = nMae;
                objDen.Placa               = placa;
                objDen.MunicipioCarro      = municipioPlaca;
                objDen.Renavam             = renavam;
                objDen.Chassi              = chassi;
                objDen.NumMotor            = numMotor;
                objDen.DataAltMotor        = dataAltMotor;
                objDen.Tipo                = tipo;
                objDen.Procedencia         = procedencia;
                objDen.Combustivel         = combustivel;
                objDen.Cor                 = cor;
                objDen.MarcaModelo         = marcaModelo;
                objDen.CategoriaAut        = categoriaAut;
                objDen.Fabricacao          = anoFab;
                objDen.Modelo              = anoMod;
                objDen.Logradouro          = logradouro;
                objDen.Numero              = numero;
                objDen.Complemento         = complemento;
                objDen.CEP                 = cep;
                objDen.Bairro              = bairro;
                objDen.Licenciamento       = licenciamento;
                objDen.DataLicenciamento   = dataLicenciamento;
                objDen.DataEmissaoCRV      = dataEmissaoCRV;

                detranRepository.Insert(objDen);

                string objjsonData = JsonConvert.SerializeObject(objDen, new JsonSerializerSettings {
                    Formatting = Formatting.Indented
                });

                //System.IO.File.WriteAllText(@"C:\Users\favar\Desktop\Texto\Detran.txt", objjsonData);

                return(objjsonData);
            }
        }