Close() public method

public Close ( ) : void
return void
Esempio n. 1
0
        public void GenerarReporteCompleto()
        {
            string[] piesPagina = {
                                      "PAGO", "CONSECUTIVO DE PEDIDOS",
                                      "PROVEEDOR", "ACUSE DE RECIBO", "EXPEDIENTE","COMPRADOR"
                                  };

            var filePedidoCompleto = Path.GetTempFileName() + ".pdf";
            var concatenate = new PdfConcatenate(new FileStream(filePedidoCompleto, FileMode.Create));

            for (var numReporte = 0; numReporte < piesPagina.Count(); numReporte++)
            {
                this.piePagina = piesPagina[numReporte];
                var fileReporte = GenerarReporte();
                var reporte = new PdfReader(fileReporte);
                concatenate.AddPages(reporte);
                File.Delete(fileReporte);
            }

            concatenate.Close();

            Process.Start("cmd", "/c " + filePedidoCompleto);
        }
Esempio n. 2
0
        static void SearchAndMerge(string srcSplitPdfPath, string dstFinalPdfPath)
        {
            // Regex search strings
            var searchText = @"((NH)[A-Z0-9]{5})";
            var reg = new Regex(searchText);

            foreach (var file in Directory.EnumerateFiles(srcSplitPdfPath, "*.pdf"))
            {
                using (var pdfReader = new PdfReader(file))
                {
                    for (var page = 1; page <= pdfReader.NumberOfPages; page++)
                    {
                        //Get the text from the page
                        var currentText = PdfTextExtractor.GetTextFromPage(pdfReader, page, new SimpleTextExtractionStrategy());

                        //currentText.IndexOf("", StringComparison.InvariantCultureIgnoreCase);
                        currentText.Contains("");

                        //Match our pattern against the extracted text
                        //var matches = reg.Matches(currentText);
                        var match = reg.Match(currentText);

                        //This is the file path that we want to target
                        var destFile = Path.Combine(dstFinalPdfPath, match.ToString() + ".pdf");

                        //If the file doesn't already exist then just copy the file and move on
                        if (!File.Exists(destFile))
                        {
                            System.IO.File.Copy(file, destFile);
                            continue;
                        }

                        using (var ms = new MemoryStream())
                        {
                            //Use a wrapper helper provided by iText
                            var cc = new PdfConcatenate(ms);

                            //Open for writing
                            cc.Open();

                            //Import the existing file
                            using (var subReader = new PdfReader(destFile))
                            {
                                cc.AddPages(subReader);
                            }

                            using (var subReader = new PdfReader(file))
                            {
                                cc.AddPages(subReader);
                            }

                            //Close for writing
                            cc.Close();

                            //Erase our exisiting file
                            File.Delete(destFile);

                            //Write our new file
                            File.WriteAllBytes(destFile, ms.ToArray());
                        }
                    }
                }
            }
        }