Guest User

Untitled

a guest
Oct 18th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. Failed to load PDF document.
  2.  
  3. this._comms.downLoadCertificate(certificateNumber).subscribe((data) => {
  4. this.downloadFile(data);
  5. this.completeLoad();
  6. }
  7.  
  8. downloadFile(response: any) {
  9. var fileContent = new Blob([response.fileContents], {type:
  10. 'application/pdf' });
  11. FileSaver.saveAs(fileContent, response.fileDownloadName);
  12. }
  13.  
  14. downLoadCertificate(certificateNumber: string) {
  15. let headers = new Headers({
  16. responseType: ResponseContentType.ArrayBuffer
  17. });
  18. return this._http.get(`${baseUrl}api/UserAdmin/DownloadCertificate/${certificateNumber}`
  19. , { headers: headers })
  20. .map(res => res.json())//
  21. .catch(super.handleError)
  22.  
  23. [HttpGet]
  24. [Route("api/UserAdmin/DownloadCertificate/{certificateNumber}")]
  25. public System.Web.Mvc.FileResult DownloadCertificate(string certificateNumber)
  26. {
  27. string path = HttpContext.Current.Server.MapPath("~/Certificates/certificate_#" + certificateNumber + ".pdf");
  28.  
  29. System.Web.Mvc.FileContentResult result = new System.Web.Mvc.FileContentResult(File.ReadAllBytes(path), "application/pdf")
  30. {
  31. FileDownloadName = certificateNumber + ".pdf"
  32. };
  33.  
  34. return result;
  35.  
  36. }
Add Comment
Please, Sign In to add comment