printDocument(documentId:string): void{
this.uiService.isLoading.next(true);
this.printDocumentService
.getDocumentPDFBase64( this.solicitud.solicitudId + "", this.solicitud.solicitudId )
.subscribe(
(response: any)=>{
const pdf = response.datos;
this.sendPrintPDF(pdf);
this.uiService.isLoading.next(false);
},
(error)=>{
console.log(error);
this.uiService.isLoading.next(false);
}
);
}
sendPrintPDF(pdfBase64:string) {
const url = window.URL.createObjectURL(this.getBlobUrl(pdfBase64))
var iframe = document.createElement('iframe');
iframe.src = url;
iframe.title = "PrintDocument"
iframe.style.display = 'none';
document.body.appendChild(iframe);
iframe.onload = function() {
setTimeout(function() {
iframe.focus();
iframe.contentWindow.print();
}, 1);
};
}
private getBlobUrl(pdfBase64:string):Blob{
const byteArray = new Uint8Array(atob(pdfBase64).split('').map(char => char.charCodeAt(0)));
var blob = new Blob([byteArray], {type: 'application/pdf'});
return blob;
}