added generation function for generate pdf
This commit is contained in:
31
src/app/services/file.service.ts
Normal file
31
src/app/services/file.service.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import {HttpResponse} from "@angular/common/http";
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class FileService {
|
||||
getFilenameFromHttpResponse(httpResponse: HttpResponse<Blob>) {
|
||||
const contentDispositionHeader = httpResponse.headers.get('Content-Disposition');
|
||||
// console.log(contentDispositionHeader);
|
||||
let result = contentDispositionHeader.split(';')[1].trim().split('=')[1];
|
||||
// Removing the " from the after trim operation
|
||||
result = result.replace(/"/g, '');
|
||||
// Removing . from filename
|
||||
// return result.replace(/./g, '_');
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
downloadBlob(data: HttpResponse<Blob>) {
|
||||
const url = window.URL.createObjectURL(data.body);
|
||||
const anchor = document.createElement('a');
|
||||
|
||||
anchor.download = this.getFilenameFromHttpResponse(data);
|
||||
anchor.href = url;
|
||||
anchor.click();
|
||||
anchor.remove();
|
||||
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user