using DocumentOperator.Application.ConvertFromPdfA; using DocumentOperator.Application.ConvertToPdfA; using DocumentOperator.Domain.Common.Exceptions; using MediatR; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; namespace DocumentOperator.API.Controllers; /// /// Controller for PDF conversion operations (PDF ? PDF/A) /// [ApiController] [Route("api/pdf/conversion")] [Obsolete("This endpoint is not implemented yet.")] public class PdfConversionController(IMediator mediator) : ControllerBase { /// /// Converts a standard PDF to PDF/A format. /// Supports multipart/form-data file upload. /// /// The PDF file to convert /// Target PDF/A level (e.g., "PDF/A-1b", "PDF/A-2b", "PDF/A-3b") /// Cancellation token /// PDF/A compliant document /// PDF converted to PDF/A successfully /// Invalid input (file missing, not a PDF, or invalid PDF/A level) /// Internal server error during PDF processing [Obsolete("This endpoint is not implemented yet.")] [HttpPost("to-pdfa")] [Consumes("multipart/form-data")] [ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] public async Task ConvertToPdfAFromFile( IFormFile file, [FromQuery] string pdfALevel = "PDF/A-3b", CancellationToken cancellationToken = default) { if (file == null || file.Length == 0) { throw new BadRequestException("PDF file is required"); } // Use IFormFile stream directly (no intermediate byte[] conversion) using var pdfStream = file.OpenReadStream(); // Send command to MediatR var command = new ConvertToPdfACommand { PdfStream = pdfStream, PdfALevel = pdfALevel }; byte[] resultPdf = await mediator.Send(command, cancellationToken); // Return PDF/A file return File(resultPdf, "application/pdf", "converted-pdfa.pdf"); } /// /// Converts a standard PDF to PDF/A format. /// Supports Base64-encoded PDF via JSON payload. /// /// Request containing Base64-encoded PDF and PDF/A level /// Cancellation token /// PDF/A compliant document /// PDF converted to PDF/A successfully /// Invalid input (Base64 format error, not a PDF, or invalid PDF/A level) /// Internal server error during PDF processing [Obsolete("This endpoint is not implemented yet.")] [HttpPost("to-pdfa")] [Consumes("application/json")] [ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] public async Task ConvertToPdfAFromBase64( [FromBody] ConvertToPdfARequest request, CancellationToken cancellationToken = default) { // Convert Base64 PDF to stream byte[] pdfBytes; try { pdfBytes = Convert.FromBase64String(request.Base64Pdf); } catch (FormatException ex) { throw new BadRequestException("Invalid Base64 PDF format: " + ex.Message); } using var pdfStream = new MemoryStream(pdfBytes); // Send command to MediatR var command = new ConvertToPdfACommand { PdfStream = pdfStream, PdfALevel = request.PdfALevel ?? "PDF/A-3b" }; byte[] resultPdf = await mediator.Send(command, cancellationToken); // Return PDF/A file return File(resultPdf, "application/pdf", "converted-pdfa.pdf"); } /// /// Converts a PDF/A document to a standard PDF (removes PDF/A restrictions). /// Supports multipart/form-data file upload. /// /// The PDF/A file to convert /// Cancellation token /// Standard PDF document /// PDF/A converted to standard PDF successfully /// Invalid input (file missing, not a PDF) /// Internal server error during PDF processing [Obsolete("This endpoint is not implemented yet.")] [HttpPost("from-pdfa")] [Consumes("multipart/form-data")] [ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] public async Task ConvertFromPdfAFromFile( IFormFile file, CancellationToken cancellationToken = default) { if (file == null || file.Length == 0) { throw new BadRequestException("PDF/A file is required"); } // Use IFormFile stream directly (no intermediate byte[] conversion) using var pdfStream = file.OpenReadStream(); // Send command to MediatR var command = new ConvertFromPdfACommand { PdfStream = pdfStream }; byte[] resultPdf = await mediator.Send(command, cancellationToken); // Return standard PDF file return File(resultPdf, "application/pdf", "converted-pdf.pdf"); } /// /// Converts a PDF/A document to a standard PDF (removes PDF/A restrictions). /// Supports Base64-encoded PDF via JSON payload. /// /// Request containing Base64-encoded PDF/A /// Cancellation token /// Standard PDF document /// PDF/A converted to standard PDF successfully /// Invalid input (Base64 format error, not a PDF) /// Internal server error during PDF processing [Obsolete("This endpoint is not implemented yet.")] [HttpPost("from-pdfa")] [Consumes("application/json")] [ProducesResponseType(typeof(FileContentResult), StatusCodes.Status200OK)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status500InternalServerError)] public async Task ConvertFromPdfAFromBase64( [FromBody] ConvertFromPdfARequest request, CancellationToken cancellationToken = default) { // Convert Base64 PDF to stream byte[] pdfBytes; try { pdfBytes = Convert.FromBase64String(request.Base64Pdf); } catch (FormatException ex) { throw new BadRequestException("Invalid Base64 PDF format: " + ex.Message); } using var pdfStream = new MemoryStream(pdfBytes); // Send command to MediatR var command = new ConvertFromPdfACommand { PdfStream = pdfStream }; byte[] resultPdf = await mediator.Send(command, cancellationToken); // Return standard PDF file return File(resultPdf, "application/pdf", "converted-pdf.pdf"); } } /// /// Request DTO for converting PDF to PDF/A /// public record ConvertToPdfARequest { /// /// PDF document encoded as Base64 string /// /// JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c... public required string Base64Pdf { get; init; } /// /// Target PDF/A level (default: "PDF/A-3b") /// /// PDF/A-3b public string? PdfALevel { get; init; } } /// /// Request DTO for converting PDF/A to PDF /// public record ConvertFromPdfARequest { /// /// PDF/A document encoded as Base64 string /// /// JVBERi0xLjQKJeLjz9MKMSAwIG9iago8PC9UeXBlL0NhdGFsb2c... public required string Base64Pdf { get; init; } }