Exemple #1
0
        public async Task <IActionResult> GenerateFromHtmlString([ModelBinder(BinderType = typeof(JsonModelBinder))] PdfOptions options, [FromForm] string htmlString)
        {
            try
            {
                if (string.IsNullOrWhiteSpace(htmlString))
                {
                    return(BadRequest());
                }

                var pdfResult = await _pdfService.GeneratePdfFromHtmlStringAsync(htmlString, 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));
            }
        }