AngularJS generation of PDF

1

Good morning.

I'm working with angularjs version 1.5, and am having trouble generating PDF. The response gets a byte array would like some help.

this.TesteService.relatorio().$promise.then((response) => {
        console.log('response',response);
        var array = Object.values(response);
        console.log('array',array);
        var file = new Blob(array, {type: 'application/pdf'});
        console.log('file',file);
        var fileURL = URL.createObjectURL(file);
        console.log('fileURL',fileURL);
        this.$window.open(fileURL);
    });

How do I currently display the sheets of the file but they are blank and the error occurs:

  

Error: Command token too long: 128

    
asked by anonymous 22.11.2016 / 12:06

1 answer

1

Hello after a lot of research, and suggestions in other places I discovered the problem and a solution.

1 - The problem - My query method returned a base64 String from my backend which when it arrived at then it became an object consisting of a key (sequence number) and value (a character of my String) and even converting it to array did not work.

The solution - I still do not know why the transformation described above occurs but one of the solutions I found was:

$http({
    url: url,
    method: tipoRequest,
    data: param
})
.success((response) => {
    download('data:' + tipoArquivo + ';base64,' + response, nomeArquivo, tipoArquivo);
})
.error((response) => {
    console.log('error',response);
});

I used a lib called download.js for control, it helped a lot.

Thanks for the help.

    
24.11.2016 / 16:54