Angularjs generation of PDF

Asked

Viewed 618 times

1

Good morning.

I am working with Angularjs version 1.5, and am having trouble generating PDF. Response receives 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);
    });

As I do currently displays the file sheets but they are blank and error occurs:

Error: Command token Too long: 128

  • Try it this way: var pdfAsDataUri = "data:application/pdf;base64,"+array ;
window.open(pdfAsDataUri);

  • It didn’t work, a new window opens but nothing appears. As I do currently displays the sheets of the file but they are blank and error occurs Error Error: Command token Too long: 128

  • Add this information to the question. Apparently this bug you reported is a bug from Acrobat Reader

  • All right I’ll add.

1 answer

1

Hello after much 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 back-end that when arriving at then became a Object composed of key(sequential number) and value(a character from my String) and even converting into array did not work.

2- The solution - I still don’t 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, helped a lot.

There are other ways of solving for me this has already served, I would like if possible that someone explains to me why the situation I described in item 1 occurs.

I appreciate the help.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.