public string ExtrairTextoConcatenado(byte[] arquivoBytes, IEnumerable <int> paginas)
        {
            // validações
            Validations.ArquivoValido(arquivoBytes);

            using (MemoryStream readingStream = new MemoryStream(arquivoBytes))
                using (PdfReader pdfReader = new PdfReader(readingStream))
                    using (PdfDocument pdfDocument = new PdfDocument(pdfReader))
                    {
                        if (paginas == null || paginas.Count() == 0)
                        {
                            paginas = new List <int>(Enumerable.Range(1, pdfDocument.GetNumberOfPages()));
                        }

                        string texto = "";

                        foreach (var pagina in paginas)
                        {
                            texto = texto + PdfTextExtractor.GetTextFromPage(
                                pdfDocument.GetPage(pagina),
                                new SimpleTextExtractionStrategy()
                                );
                        }

                        return(texto);
                    }
        }
        public List <KeyValuePair <int, string> > ExtrairTextoPorPaginas(byte[] arquivoBytes, IEnumerable <int> paginas)
        {
            // validações
            Validations.ArquivoValido(arquivoBytes);

            using (MemoryStream readingStream = new MemoryStream(arquivoBytes))
                using (PdfReader pdfReader = new PdfReader(readingStream))
                    using (PdfDocument pdfDocument = new PdfDocument(pdfReader))
                    {
                        if (paginas == null || paginas.Count() == 0)
                        {
                            paginas = new List <int>(Enumerable.Range(1, pdfDocument.GetNumberOfPages()));
                        }

                        var result = new List <KeyValuePair <int, string> >();

                        foreach (var pagina in paginas)
                        {
                            string pageText = PdfTextExtractor.GetTextFromPage(
                                pdfDocument.GetPage(pagina),
                                new SimpleTextExtractionStrategy()
                                );

                            result.Add(new KeyValuePair <int, string>(pagina, pageText));
                        }

                        return(result);
                    }
        }
        public PdfInfo PdfInfo(byte[] file)
        {
            Validations.ArquivoValido(file);

            using (MemoryStream memoryStream = new MemoryStream(file))
            {
                var pdfInfo = PdfInfo(memoryStream);
                memoryStream.Close();
                return(pdfInfo);
            }
        }
        public byte[] AdicionarMarcaDagua(
            byte[] arquivo, string[] texto, int tamanhoFonte = 40, string corHexa = "ff0000",
            int anguloTextoGraus = 30, float opacidade = 0.1f, int repeticoes = 3
            )
        {
            // validações
            Validations.ArquivoValido(arquivo);

            using (MemoryStream readingStream = new MemoryStream(arquivo))
                using (PdfReader pdfReader = new PdfReader(readingStream))
                    using (MemoryStream writingStream = new MemoryStream())
                        using (PdfWriter pdfWriter = new PdfWriter(writingStream))
                            using (PdfDocument pdfDocument = new PdfDocument(pdfReader, pdfWriter))
                                using (Document document = new Document(pdfDocument))
                                {
                                    Rectangle pageSize;
                                    PdfCanvas canvas;
                                    int       n         = pdfDocument.GetNumberOfPages();
                                    float     angleRads = (anguloTextoGraus * (float)Math.PI) / 180;
                                    for (int pageCounter = 1; pageCounter <= n; pageCounter++)
                                    {
                                        PdfPage page = pdfDocument.GetPage(pageCounter);
                                        pageSize = page.GetPageSize();
                                        canvas   = new PdfCanvas(page);

                                        int k = 1;
                                        for (int repetitionCounter = 0; repetitionCounter < repeticoes; repetitionCounter++)
                                        {
                                            for (int textCounter = 0; textCounter < texto.Length; textCounter++)
                                            {
                                                // Desenhar Marca D'dágua
                                                Paragraph p = new Paragraph(texto[textCounter])
                                                              .SetFontSize(tamanhoFonte)
                                                              .SetFontColor(Hexa2Rgb(corHexa));
                                                canvas.SaveState();
                                                PdfExtGState gs1 = new PdfExtGState().SetFillOpacity(opacidade);
                                                canvas.SetExtGState(gs1);
                                                document.ShowTextAligned(
                                                    p,
                                                    pageSize.GetWidth() / 2,
                                                    (pageSize.GetHeight() / ((texto.Length * repeticoes) + 1)) * k++,
                                                    pdfDocument.GetPageNumber(page),
                                                    TextAlignment.CENTER, VerticalAlignment.MIDDLE,
                                                    angleRads
                                                    );
                                            }
                                        }
                                        canvas.RestoreState();
                                    }
                                    pdfDocument.Close();

                                    return(writingStream.ToArray());
                                }
        }