И вот что у меня есть.
В program.cs я добавил:
Код: Выделить всё
RotativaConfiguration.Setup(builder.Environment.ContentRootPath, "Rotativa");
[img]https://i.stack.imgur.com /RjlJZ.png[/img]
Код моего контроллера:
Код: Выделить всё
using Yardstick.BusinessLogic.Interfaces;
namespace Yardstick.Server.Controllers
{
[ApiController]
[Route("api/[controller]")]
public class PDFController : ControllerBase
{
private readonly IAgencyService _agencyService;
public PDFController(IAgencyService agencyService)
{
_agencyService = agencyService;
}
[HttpGet("DownloadAgencyPdfs")]
[ProducesResponseType(200, Type = typeof(FileResult))]
[ProducesResponseType(404)]
public async Task DownloadAgencyPdfsAsync([FromQuery] int[] ids)
{
var agencies = await _agencyService.GetPdfAgenciesByIdsAsync(ids);
if (agencies != null && agencies.Count > 0)
{
var page = new Rotativa.AspNetCore.ViewAsPdf("Agency.cshtml", agencies[0])
{
PageSize = Rotativa.AspNetCore.Options.Size.A4,
};
if (page != null)
{
// Convert the ViewAsPdf result to a byte array
byte[] pdfBytes = await page.BuildFile(ControllerContext);
// Return the byte array as a file for download
return File(pdfBytes, "application/pdf", "Agencies.pdf");
}
}
return NotFound();
}
}
}
Я использую неправильную версию Rotativa? (для меня веб-API .net 8).
Я получаю ссылку на объект, не найденную в строке «page.BuildFile».
Я проверил, объект страницы не равен нулю.
Будем очень признательны за любую помощь.
Подробнее здесь: https://stackoverflow.com/questions/778 ... nload-file
Мобильная версия