public async Task <IActionResult> GenerateFromImage([ModelBinder(BinderType = typeof(JsonModelBinder))] PdfOptions options) { try { using var inputData = await _multipartRequestService.GetPdfInputData(); if (inputData?.File == null) { return(BadRequest()); } if (!ImageHelper.IsImage(inputData.File.ContentType)) { return(BadRequest($@"Ugyldig MIME-type ""{inputData.File.ContentType}"".")); } var pdfResult = await _pdfService.GeneratePdfFromImageAsync(inputData, options); Response.Headers.Add("Content-Type", PdfResult.ContentType); Response.Headers.Add("Content-Length", pdfResult.FileSize.ToString()); return(File(pdfResult.Data, PdfResult.ContentType, pdfResult.FileName)); } catch (Exception exception) { _logger.LogError(exception, "En feil har oppstått!"); return(StatusCode(StatusCodes.Status500InternalServerError)); } }