Questions & Answers

Download pdf rendered from backend

I have project written in Angular + TS + Net 6 Web api.

My goal is to have button. On button click, pdf should be created in backend and PDF downloaded to user.

PDF is long report which has some variables. I heard that PDF can be generated from HTML. To simplify, lets say it looks like this:

      <div>My name is FirstParameter</div>
      <div>My age is SecondParameter</div>

I believe FileStreamResult should be returned in backend. How to achieve it (prefer without 3rd party library)


public async Task<IActionResult> DownloadPDF(Guid userId)
    var user = await _context.Users.FirstAsync(p=> == userId);
    string firstParameter = user.FirstName;
    string secondParameter = user.SecondName;

    // generating pdf as filestream

    return File(fs, "application/pdf", "random.pdf");


<a (click)="download('f58c8036-915a-4c39-bbb8-352e21eae49c')">Download pdf</a>


    download(id) {

Answers(0) :