All checks were successful
		
		
	
	Optimized Build and Deploy / remote-build-and-deploy (push) Successful in 7m36s
				
			Se elimina Puppeteer y Chromium. Se utiliza QuestPDF para mayor velocidad y sin Razor.
		
			
				
	
	
		
			46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			46 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| using Microsoft.Extensions.Logging;
 | |
| using QuestPDF.Fluent;
 | |
| using QuestPDF.Infrastructure;
 | |
| using System;
 | |
| using System.Threading.Tasks;
 | |
| 
 | |
| namespace GestionIntegral.Api.Services.Pdf
 | |
| {
 | |
|     // Una interfaz simple para mantener la inyección de dependencias
 | |
|     public interface IQuestPdfGenerator
 | |
|     {
 | |
|         Task<byte[]> GeneratePdfAsync(IDocument document);
 | |
|     }
 | |
| 
 | |
|     public class QuestPdfGenerator : IQuestPdfGenerator
 | |
|     {
 | |
|         private readonly ILogger<QuestPdfGenerator> _logger;
 | |
| 
 | |
|         public QuestPdfGenerator(ILogger<QuestPdfGenerator> logger)
 | |
|         {
 | |
|             _logger = logger;
 | |
|             
 | |
|             // --- Configuración de la licencia ---
 | |
|             QuestPDF.Settings.License = LicenseType.Community;
 | |
|             _logger.LogInformation("QuestPDF inicializado con licencia Community.");
 | |
|         }
 | |
| 
 | |
|         public async Task<byte[]> GeneratePdfAsync(IDocument document)
 | |
|         {
 | |
|             _logger.LogInformation("Generando PDF con QuestPDF para el documento de tipo {DocumentType}.", document.GetType().Name);
 | |
|             try
 | |
|             {
 | |
|                 // GeneratePdf() es síncrono, pero lo envolvemos en un Task para mantener la interfaz asíncrona.
 | |
|                 byte[] pdfBytes = await Task.Run(() => document.GeneratePdf());
 | |
|                 
 | |
|                 _logger.LogInformation("PDF generado exitosamente con QuestPDF ({Length} bytes).", pdfBytes.Length);
 | |
|                 return pdfBytes;
 | |
|             }
 | |
|             catch (Exception ex)
 | |
|             {
 | |
|                 _logger.LogError(ex, "Error durante la generación del PDF con QuestPDF.");
 | |
|                 throw;
 | |
|             }
 | |
|         }
 | |
|     }
 | |
| } |