Trying to open PDF File in Edge shows “Something's keeping this PDF file from opening” error

浪尽此生 提交于 2019-12-13 03:25:36

问题


I'm trying to open a PDF file in the Microsoft Edge browser. The PDF file is generated using jsPDF library in Angular 8. The code I've written is given below:

import { Component, OnInit } from '@angular/core';
import * as data from '../dummy.json';
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';

@Component({
  selector: 'app-create-pdf',
  templateUrl: './create-pdf.component.html',
  styleUrls: ['./create-pdf.component.css']
})
export class CreatePDFComponent implements OnInit {

  constructor() { }

  ngOnInit() {
    debugger;
    var columns = [
      {title: "ID", dataKey: "id"},
      {title: "Name", dataKey: "name"}, 
      {title: "Country", dataKey: "country"}, 
  ];

  var rows = [
      {"id": 1, "name": "Shaw", "country": "Tanzania"},
      {"id": 2, "name": "Nelson", "country": "Kazakhstan"},
      {"id": 3, "name": "Garcia", "country": "Madagascar"},
  ];

  var doc = new jsPDF('p', 'pt');
  doc.autoTable(columns, rows, {
      styles: {fillColor: [100, 255, 255]},
      columnStyles: {
        id: {fillColor: 255}
      },
      margin: {top: 60},
      beforePageContent: function(data) {
        doc.text("Header", 40, 30);
      }
  });
      let string = doc.output("datauristring");
      let file = this.dataURLtoFile(string,"Report.pdf");
      var url = URL.createObjectURL(file);
      var newWindow = window.open();
      newWindow.document.open();
      newWindow.document.write('<html><body><object data = "'+url+'" width = "100%" height = "100%" type = "application/pdf"></object></body></html>');    
    }
    dataURLtoFile(dataurl, filename) {
      var arr = dataurl.split(','),
          mime = arr[0].match(/:(.*?);/)[1],
          bstr = atob(arr[1]), 
          n = bstr.length, 
          u8arr = new Uint8Array(n);

      while(n--){
          u8arr[n] = bstr.charCodeAt(n);
      }
      return new File([u8arr], filename, {type:mime});
  }   
  }

When I run the code in Google Chrome, the file opens. But when I try it in Microsoft Edge, the screen shows "Couldn't open PDF, something's keeping this PDF from opening" error. I tried clearing the cache of the browser, but still, the error shows. Can anybody please help me by giving a solution?

N.B. I'm attaching a screenshot of the error message for your reference.

Screenshot of Error

Thanks in advance.


回答1:


Not sure whether this is the same issue you had posted 4 days ago.

PDF File generated using jsPDF doesn't show on Microsoft Edge

I again try to make research based on new error and I found that this error may occur if you had installed any other pdf viewer for viewing the pdf. It can interrupt the Edge and can cause this error.

You can try to Refer following points may help to fix this issue.

(1) Set Microsoft Edge as a default PDF viewer.

(2) Delete Cache in Microsoft Edge.

(3) Repair Microsoft Edge.

For detailed steps, you can refer link below.

Couldn’t open PDF in Edge, Something’s keeping this PDF from the opening



来源:https://stackoverflow.com/questions/59025698/trying-to-open-pdf-file-in-edge-shows-somethings-keeping-this-pdf-file-from-op

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!