-1

Hi I have the below code to achieve print functionality . The code works fine in Chrome, but doesnt work in Edge. Getting the follwing error in edge.I am building the layout in javascript in generatePDF function. enter image description here

Below is my JS code:

$scope.printRepayment = function() {
    var documentDefinition = generatePDF();                                     pdfMake.createPdf(documentDefinition).print();
      }



var generatePDF = function() {
            var repayments = $scope.repayments;
            var rows = [
              [
                { text: "Payment No", style: "tableHeader" },
                { text: "Installment", style: "tableHeader" },
              ]
            ];
            for (var i = 0; i < repayments.length; i++) {
              rows.push([
                { text: i + 1, style: "tablefirst" },
                {
                  text:
                    "AED " +
                    numberWithCommas(
                      parseFloat(repayments[i].installment).toFixed(2)
                    ),
                  style: "tableOther"
                },
              ]);
            }
            return {
              content: [
                { text: "Repayment schedule", style: "subheader" },
                {
                  style: "tableExample",
                  table: {
                    widths: ["*", "*", "*", "*", "*"],
                    body: rows
                  },
                  layout: {
                    vLineColor: function(i, node) {
                      return "#ECF3FE";
                    }
                  }
                }
              ],
              styles: {
                tabletop: {
                  margin: [10, 0, 0, 10]
                },
                tabletopHeader: {
                  fontSize: 16,
                  bold: true
                }
              }
            };
          };
TylerH
  • 20,799
  • 66
  • 75
  • 101
Nancy
  • 911
  • 7
  • 26
  • 54
  • Whats is the version of Edge that you are using? Does `pdfmake.js` supports Edge? – Master Po Dec 05 '19 at 05:24
  • Microsoft Edge 44.18362.449.0 – Nancy Dec 05 '19 at 05:24
  • `pdfMake.createPdf(documentDefinition).print();`... The `print()` method is not supported by Edge. Please check the [Browser support](https://github.com/bpampuch/pdfmake/issues/800). Edge only supports `download()` – Master Po Dec 05 '19 at 05:33
  • Thanks for the link..Is there any other way to achieve download in Edge? other than print() – Nancy Dec 05 '19 at 05:37
  • Can you try `pdfMake.createPdf(documentDefinition).download(); `? – Master Po Dec 05 '19 at 05:41
  • .download() works fine, but i need print functionality, as download just downloads and print behaviour is different. – Nancy Dec 05 '19 at 05:44

2 Answers2

0

With refer to this article, we can see that the pdfMake print() method doesn't support Edge browser. So, as a workaround, I think you could create a web page which contains the display the pdf content, then, calling the window.print(); method to print this page. Otherwise, as Master Po said, you could download the pdf file first, then, print the pdf content.

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
0

Thanks a ton @Zhi Lv - MSFT, for giving the solution in plain english and then after having discovered how to do, this is what worked for me

var pdf = pdfMake.createPdf(doc);
pdf.getBuffer(function (buffer) {
            var file = new Blob([buffer], {type: 'application/pdf'});
            var fileURL = URL.createObjectURL(file);
            window.location.href = fileURL; 
        }); // {autoPrint: true});          

the pdf file generated is converted into a blob and the url of that file is then opened up as a new window, shows the pdf doc and can be printed

Yet not sure how autoPrint works, will need to work a bit more