'Display Pdf in browser using nestJs

How to correct display title of pdf

     @Get(':id([0-9]+)/show_pdf')
  @ApiOkResponse({ type: SuccessResponseDto })
  async showPdf(@Param('id') id: number, @Res() res) {
    const report = await Report.findOne(id)

    if (!report) {
      throw new NotFoundException(`Not found report id: ${id}`)
    }

    res.set({
      'Content-Type': 'application/pdf',
      'Content-Disposition': `inline; filename=${report.attachments}`,
    })
    if (fs.existsSync(this.uploadRootPath + '/pdf/' + report.attachments)) {
      fs.readFile(join(this.uploadRootPath + '/pdf', report.attachments), (err, pdf) => {
        res.end(pdf)
      })
    } else {
      throw new BadRequestException('Invalid pdf')
    }
  }

I got

enter image description here

But I want custom title

Like this

https://www.orimi.com/pdf-test.pdf

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source