private void btnRotar_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtAngulo.Text)) { MessageBox.Show("Introduzca el angulo que debe de rotar el documento."); } if (lstFicheros.SelectedItems.Count == 1) { string ficheroOrigen = lstFicheros.SelectedItems[0].SubItems[1].Text; PdfTools.RotarPDF(txtFicheroDestino.Text, ficheroOrigen, int.Parse(txtAngulo.Text)); } else { if (lstFicheros.Items.Count > 1) { MessageBox.Show("Seleccione el documento que quiere rotar."); } else { lstFicheros.Items[0].Selected = true; string ficheroOrigen = lstFicheros.SelectedItems[0].SubItems[1].Text; PdfTools.RotarPDF(txtFicheroDestino.Text, ficheroOrigen, int.Parse(txtAngulo.Text)); } } }
public async Task <IActionResult> BuscarExpressoesRegulares(IFormFile arquivo, [FromForm] IEnumerable <string> expressoesRegulares, [FromForm] IEnumerable <int> paginas) { if (arquivo.Length > 0) // analisar de tirar essa validacao aqui e jogar para dentro de obter arquivo { var arquivoBytes = await PdfTools.ObterArquivo(arquivo); var response = CarimboCore.BuscarExpressoesRegulares(arquivoBytes, expressoesRegulares, paginas); return(Ok(new ApiResponse <string>(200, "success", response))); } return(BadRequest()); }
public async Task <IActionResult> IsPdf(IFormFile arquivo) { if (arquivo.Length > 0) { var arquivoBytes = await PdfTools.ObterArquivo(arquivo); var result = TransformaPdfCore.IsPdf(arquivoBytes); return(Ok(new ApiResponse <bool>(200, "success", result))); } return(BadRequest()); }
public async Task <IActionResult> HtmlPdfByFile(IFormFile arquivo) { if (arquivo.Length > 0) { var arquivoBytes = await PdfTools.ObterArquivo(arquivo); var output = TransformaPdfCore.HtmlPdf(arquivoBytes); return(File(output, "application/octet-stream")); } return(BadRequest()); }
public async Task <IActionResult> ExtrairTextoConcatenado(IFormFile arquivo, [FromForm] IEnumerable <int> paginas) { if (arquivo.Length > 0) { var arquivoBytes = await PdfTools.ObterArquivo(arquivo); var response = ExtracaoCore.ExtrairTextoConcatenado(arquivoBytes, paginas); return(Ok(new ApiResponse <string>(200, "success", response))); } return(BadRequest()); }
public async Task <IActionResult> PossuiRestricoes(IFormFile arquivo) { if (arquivo.Length > 0) { var arquivoByteArray = await PdfTools.ObterArquivo(arquivo); var response = TransformaPdfCore.PossuiRestricoes(arquivoByteArray); return(Ok(new ApiResponse <bool>(200, "success", response))); } return(BadRequest()); }
public async Task <IActionResult> ConcatenarPdfs(IFormFileCollection arquivos) { if (arquivos.Count() > 1) { var arquivosBytes = await PdfTools.ObterArquivos(arquivos); var output = TransformaPdfCore.PdfConcatenation(arquivosBytes); return(File(output, "application/octet-stream")); } return(BadRequest()); }
public async Task <IActionResult> RemoverAnotacoes(IFormFile arquivo) { if (arquivo.Length > 0) { var arquivoBytes = await PdfTools.ObterArquivo(arquivo); var arquivoLimpo = TransformaPdfCore.RemoveAnnotations(arquivoBytes); return(File(arquivoLimpo, "application/octet-stream")); } return(BadRequest()); }
public async Task <IActionResult> PaginacaoDePDF(IFormFile arquivo, [FromForm] int itensPorPagina, [FromForm] int pagina) { if (arquivo.Length > 0) { var arquivoBytes = await PdfTools.ObterArquivo(arquivo); var output = TransformaPdfCore.PdfPagination(arquivoBytes, itensPorPagina, pagina); return(File(output, "application/octet-stream")); } return(BadRequest()); }
public async Task <IActionResult> ConcatenarUrlEArquivo([FromForm] string url, IFormFile arquivo) { if (arquivo.Length > 0) { byte[] documentoBytes = await PdfTools.ObterArquivo(arquivo); var output = await TransformaPdfCore.ConcatenarUrlEArquivo(url, documentoBytes); return(File(output, "application/octet-stream")); } return(BadRequest()); }
public async Task <IActionResult> IsPdfa(IFormFile arquivo) { if (arquivo.Length > 0) { var arquivoBytes = await PdfTools.ObterArquivo(arquivo); TransformaPdfCore.IsPdf(arquivoBytes); TransformaPdfCore.IsPdfa1b(arquivoBytes); return(Ok()); } return(BadRequest()); }
protected virtual void Dispose(bool disposing) { if (_isDisposed || !disposing) { return; } if (_pdfTools != null) { ((IDisposable)_pdfTools).Dispose(); _pdfTools = null; } _isDisposed = true; }
private void btnJuntar_Click(object sender, EventArgs e) { ArrayList lstFiles = null; if (lstFicheros.Items.Count > 0) { lstFiles = new ArrayList(); for (int index = 0; index < lstFicheros.Items.Count; index++) { lstFiles.Add(lstFicheros.Items[index].SubItems[1].Text); } } PdfTools.MergePDF(txtFicheroDestino.Text, (string[])lstFiles.ToArray(typeof(string))); }
private static void Init() { var builder = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("secrets/appsettings.secrets.json", optional: true) .AddEnvironmentVariables(); IConfigurationRoot Configuration = builder.Build(); // Retrieve configuration from sections ApplicationSettings.ConnectionString = Configuration.GetSection("ApplicationSettings:ConnectionString")?.Value; ApplicationSettings.DatabaseId = Configuration.GetSection("ApplicationSettings:DatabaseId")?.Value; ApplicationSettings.ReportCollection = Configuration.GetSection("ApplicationSettings:ReportCollection")?.Value; ApplicationSettings.RabbitMQUsername = Configuration.GetSection("ApplicationSettings:RabbitMQUsername")?.Value; ApplicationSettings.RabbitMQPassword = Configuration.GetSection("ApplicationSettings:RabbitMQPassword")?.Value; ApplicationSettings.RabbitMQHostname = Configuration.GetSection("ApplicationSettings:RabbitMQHostname")?.Value; ApplicationSettings.RabbitMQPort = Convert.ToInt16(Configuration.GetSection("ApplicationSettings:RabbitMQPort")?.Value); ApplicationSettings.DispatchQueueName = Configuration.GetSection("ApplicationSettings:DispatchQueueName")?.Value; ApplicationSettings.KeyVaultCertificateName = Configuration.GetSection("ApplicationSettings:KeyVaultCertificateName")?.Value; ApplicationSettings.KeyVaultClientId = Configuration.GetSection("ApplicationSettings:KeyVaultClientId")?.Value; ApplicationSettings.KeyVaultClientSecret = Configuration.GetSection("ApplicationSettings:KeyVaultClientSecret")?.Value; ApplicationSettings.KeyVaultIdentifier = Configuration.GetSection("ApplicationSettings:KeyVaultIdentifier")?.Value; ApplicationSettings.KeyVaultEncryptionKey = Configuration.GetSection("ApplicationSettings:KeyVaultEncryptionKey")?.Value; ApplicationSettings.SendGridAPIKey = Configuration.GetSection("ApplicationSettings:SendGridAPIKey")?.Value; mongoDBConnectionInfo = new MongoDBConnectionInfo() { ConnectionString = ApplicationSettings.ConnectionString, DatabaseId = ApplicationSettings.DatabaseId, UserCollection = ApplicationSettings.ReportCollection }; keyVaultConnectionInfo = new KeyVaultConnectionInfo() { CertificateName = ApplicationSettings.KeyVaultCertificateName, ClientId = ApplicationSettings.KeyVaultClientId, ClientSecret = ApplicationSettings.KeyVaultClientSecret, KeyVaultIdentifier = ApplicationSettings.KeyVaultIdentifier }; using (KeyVaultHelper keyVaultHelper = new KeyVaultHelper(keyVaultConnectionInfo)) { secret = keyVaultHelper.GetVaultKeyAsync(ApplicationSettings.KeyVaultEncryptionKey).Result; } pdfTools = new PdfTools(); converter = new SynchronizedConverter(pdfTools); }
public async Task <IActionResult> AdicionarMarcaDaguaByFile( IFormFile arquivo, [FromForm] string[] texto, [FromForm] int tamanhoFonte = 40, [FromForm] string corHexa = "ff0000", [FromForm] int anguloTextoGraus = 30, [FromForm] float opacidade = 0.1f, [FromForm] int repeticoes = 3 ) { if (arquivo.Length > 0) { var arquivoByteArray = await PdfTools.ObterArquivo(arquivo); var arquivoMarcado = CarimboCore.AdicionarMarcaDagua( arquivoByteArray, texto, tamanhoFonte, corHexa, anguloTextoGraus, opacidade, repeticoes ); return(File(arquivoMarcado, "application/pdf")); } return(BadRequest()); }
// Efetua o split do arquivo pdf private void _processPdf(TOArqPdf to) { PdfReader reader = null; Document sourceDocument = null; PdfCopy pdfCopy = null; PdfImportedPage page = null; int currentCod = 0; string arqname; string completePath; try { logger.Info("============================================================"); logger.Info("Processando arquivo: " + to.FileName); reader = new PdfReader(to.FileName); sourceDocument = new Document(reader.GetPageSizeWithRotation(1)); string pathTimeStamp = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss-fff"); completePath = to.Config.PathProcessed + "\\" + pathTimeStamp; if (!Directory.Exists(completePath)) { Directory.CreateDirectory(completePath); } string onlyFile = to.FileName.Substring(to.FileName.LastIndexOf("\\") + 1); int pageCount = reader.NumberOfPages; for (int i = 1; i <= pageCount; i++) { ITextExtractionStrategy strategy = new SimpleTextExtractionStrategy(); string currentText = PdfTextExtractor.GetTextFromPage(reader, i, strategy); currentText = Encoding.UTF8.GetString(ASCIIEncoding.Convert(Encoding.Default, Encoding.UTF8, Encoding.Default.GetBytes(currentText))); int idCliente = 0; switch (to.Config.Type) { case TypeWatcher.BMF: idCliente = PdfTools.ExtractBMFClientID(currentText); break; case TypeWatcher.BOVESPA: idCliente = PdfTools.ExtractBovespaClientID(currentText); break; case TypeWatcher.POSICAO_BMF: idCliente = PdfTools.ExtractPosicaoBmfClientID(currentText); break; } logger.InfoFormat("Arquivo: [{0}] Pagina: [{1}] IdCliente [{2}]", onlyFile, i.ToString("D5"), idCliente.ToString("D8")); if (idCliente >= 0) { if (currentCod != idCliente) { // Salvar o anterior if (pdfCopy != null) { pdfCopy.Close(); sourceDocument.Close(); sourceDocument = new Document(reader.GetPageSizeWithRotation(i)); } arqname = string.Format("{0}\\{1}\\{2}.pdf", to.Config.PathProcessed, pathTimeStamp, idCliente.ToString("D8")); if (File.Exists(arqname)) { arqname = string.Format("{0}\\{1}\\{2}-{3}.pdf", to.Config.PathProcessed, pathTimeStamp, idCliente.ToString("D8"), new Random().Next(1, 100000).ToString("D6")); } pdfCopy = new PdfCopy(sourceDocument, new FileStream(arqname, FileMode.Create)); sourceDocument.Open(); currentCod = idCliente; } page = pdfCopy.GetImportedPage(reader, i); pdfCopy.AddPage(page); // Verifica se pagina corrente eh igual ao numero de paginas, para fechar o arquivo if (i == pageCount) { pdfCopy.Close(); pdfCopy = null; } } else { logger.Error("Não foi possivel extrair o codigo de cliente da pagina: " + i); continue; } } EmailManager.Instance.ProcessEmailPath(completePath, to.Config); } catch (Exception ex) { logger.Error("Problemas no processamento do Pdf: " + ex.Message, ex); } finally { if (reader != null) { reader.Close(); reader = null; } if (sourceDocument != null) { sourceDocument.Close(); sourceDocument = null; } if (pdfCopy != null) { pdfCopy.Close(); pdfCopy = null; } page = null; } }
public static SynchronizedConverter SyncConverter(this PdfTools _) => new SynchronizedConverter(_);
public static BasicConverter Converter(this PdfTools _) => new BasicConverter(_);
public PdfGenerator() { _isDisposed = false; _pdfTools = new PdfTools(); _synchronizedConverter = new SynchronizedConverter(_pdfTools); }