I'm trying to show a PDF with Typescript, it comes to base64 and I decode it to see the array of bytes.
The PDF of opens, but blank, the pages coincide, but it is all without content.
The content in base64 I leave here PDF in Base64
Regarding the code I use to do it, it is as follows.
In the service there is a call to the API, which is the one that returns the content.
getDescargaFactura(idFacturaVenta): Observable<any> {
const httpHeaders = new HttpHeaders({
'Content-Type': 'application/json',
Authorization: this.token
});
const options = {
headers: httpHeaders
};
const body = { IdFactura: idFacturaVenta };
return this.http.post<any>(this.urlApi + 'Facturas/GetFacturasPDF', body, options);
}
And in the controlled one, I show the PDF.
descargaFactura(datos: any) {
this._facturasService
.getDescargaFactura(datos.IdFacturaVentaCabecera)
.subscribe(data => {
this.pdfFactura = this._funcionesService.decodificarToken(data);
const newBlob = new Blob([window.atob(this.pdfFactura.PDFBase64)], {
type: 'application/pdf'
});
if (window.navigator && window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveOrOpenBlob(newBlob);
return;
}
const datos = window.URL.createObjectURL(newBlob);
const link = document.createElement('a');
link.href = datos;
link.download = 'file.pdf';
link.click();
});
}
I have done several tests and I can only show the PDF without content, I do not know if it is due to a coding issue or by Angular himself.