尝试在Edge中打开PDF文件会显示“某些阻止打开此PDF文件".错误 [英] Trying to open PDF File in Edge shows "Something's keeping this PDF file from opening" error

查看:140
本文介绍了尝试在Edge中打开PDF文件会显示“某些阻止打开此PDF文件".错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Microsoft Edge浏览器中打开PDF文件. PDF文件是使用Angular 8中的jsPDF库生成的.我编写的代码如下:

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});
  }   
  }

当我在Google Chrome浏览器中运行代码时,文件会打开.但是,当我在Microsoft Edge中尝试该程序时,屏幕上显示无法打开PDF,导致此PDF无法打开" 错误.我尝试清除浏览器的缓存,但仍然显示错误.任何人都可以通过提供解决方案来帮助我吗?

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.

错误截图

谢谢.

推荐答案

不确定这是否与您4天前发布的问题相同.

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

使用jsPDF生成的PDF文件未显示在Microsoft Edge上

我再次尝试根据新的错误进行研究,发现如果您安装了任何其他pdf查看器来查看pdf,则可能会发生此错误.它可能会中断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)将Microsoft Edge设置为默认的PDF查看器.

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

(2)删除Microsoft Edge中的缓存.

(2) Delete Cache in Microsoft Edge.

(3)修复Microsoft Edge.

(3) Repair Microsoft Edge.

有关详细步骤,请参阅下面的链接.

For detailed steps, you can refer link below.

可以在Edge中没有打开PDF,有些使该PDF不能打开

这篇关于尝试在Edge中打开PDF文件会显示“某些阻止打开此PDF文件".错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆