public ActionResult GetBarcode([FromRoute] int id) { byte[] bytes; using (var stream = new MemoryStream()) { _pdfService.PrintBarcodeToPdf(stream, id); bytes = stream.ToArray(); } string guid = string.Format("{0,10:D6}", id).Trim(); var fileName = $"barcode_{guid}_{GenerateRandomDigitCode(2)}.pdf"; return(File(bytes, "application/pdf", fileName)); }