Skip to content

Instantly share code, notes, and snippets.

@nicoavila
Created February 11, 2019 19:29
Show Gist options
  • Save nicoavila/6dda8beb532aa2da4e6e98a4ddca1c27 to your computer and use it in GitHub Desktop.
Save nicoavila/6dda8beb532aa2da4e6e98a4ddca1c27 to your computer and use it in GitHub Desktop.
/*
* ADVERTENCIA:
* - Asume el uso de Angular
*/
public descargarCertificado() {
this.http.get('/genera_certificado', {
responseType: 'arraybuffer'
}).subscribe((data:any) => this.descargarArchivo(data));
}
public descargarArchivo(datos: any) {
const blob = new Blob([data], {type: 'application/pdf'});
const url = window.URL.createObjectURL(blob);
window.open(url);
}
/*
* ADVERTENCIA:
* - Esto asume la instalación de WKHTMLTOPDF en el servidor (binario agregado al PATH)
* - Asume el uso de express. Esto es solo una ruta de ejemplo
*/
const wkhtmltopdf = require('wkhtmltopdf');
router.get('/genera_certificado', (req, res) => {
const body = '<p>Hola! Soy HTML</p>';
wkhtmltopdf(body , options).pipe(res);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment