0

I am using FileSaver.js to download a PDF - File.

Now I'd like to open the PDF in a new tab. How can I achieve this?

        vm.getDocument = function (voucherNumber) {
            var pdfName = "XXXXXX" + voucherNumber+".pdf";
            return DownloadService.getDocument(voucherNumber)
            .then(function (response) {
                var pdf = new Blob([response.data], {type: 'application/pdf'});
                //var pdfURL = $window.URL.createObjectURL(pdf);
                saveAs(pdf, pdfName);

                ///var popUp = $window.open(pdfURL, '_blank');
                //check for active popup blocker
//              if (popUp == null || typeof(popUp)=='undefined') {
//                  alertify.alert($translate.instant('DOWNLOADS_POPUP_BLOCKER'));
//              } else {
//                  popUp.focus();
//              }
            })
            .catch(function (error) {
                alertify.logPosition("bottom right").error(voucherNumber + $translate.instant('VKI_DOCUMENT_NOT_FOUND'));
            })
        };
s.stkvc
  • 127
  • 1
  • 2
  • 12
  • Try un-commenting the lines that open it in a new tab. – georgeawg Sep 05 '19 at 16:24
  • @georgeawg that downloads the pdf and opens it, but it is not named correctly. Therefore im using saveAs from FileSaver.js – s.stkvc Sep 05 '19 at 16:35
  • Possible duplicate of [Open PDF in new tab, saving file gives wrong file name](https://stackoverflow.com/questions/56546106/open-pdf-in-new-tab-saving-file-gives-wrong-file-name). – georgeawg Sep 05 '19 at 21:30

0 Answers0