本文介绍了当通过数据网址显示PDF时,Firefox挂起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用在浏览器中创建PDF的应用程序。我想在另一个标签页/窗口中显示这个pdf。

  function open_data_uri_window(url){
var html =' < html> +
< style> html,body {padding:0;保证金:0; } iframe {width:100%;身高:100% border = 0;}< / style>'+
'< body>'+
'< p>新的观看者< / p> +
< iframe type = application / pdfsrc ='+ url +'>< / iframe>'+
'< / body>< / html>';

var a = window.open(about:blank,Zupfnoter);
a.document.write(html);
.document.close();



$ b

它在Chrome(60.0.3112.90)中工作正常,但在Firefox(54.0 .1 64位MacOs)。那里的窗口挂起。

解决方案

原因是PDF.js(第331行)尝试从url中提取建议的文件名。这个正则表达式根据dataurl挂起。



解决方法是在datauri字符串中指定一个名称,以便始终找到一个可接受的名称,如注释1

 函数open_data_uri_window(url){
var url_with_name = url.replace(data:application / pdf;,data:application / pdf; name = myname.pdf;)
var html ='< html>'+
'< style> ; html,body {padding:0;保证金:0; } iframe {width:100%;身高:100% border = 0;}< / style>'+
'< body>'+
'< p>新的观看者< / p> +
< iframe type = application / pdfsrc ='+ url_with_name +'>< / iframe>'+
'< / body>< / html>';
var a = window.open(about:blank,Zupfnoter);
a.document.write(html);
.document.close();

code


提示:Chrome浏览器的内建查看器不支持指定的名称


I have an app which creates pdf in the browser using jspdf. I want to show this pdf in another tab/window.

function open_data_uri_window(url) {
   var html = '<html>' +
     '<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;}  </style>' +
    '<body>' +
    '<p>new viewer</p>' +
    '<iframe type="application/pdf" src="' + url + '"></iframe>' +
    '</body></html>';

  var a = window.open("about:blank", "Zupfnoter");
  a.document.write(html);
  a.document.close();
}

It works fine in chrome (60.0.3112.90) but not on Firefox (54.0.1 64 bit MacOs). There the window hangs.

解决方案

Reason is that PDF.js (line 331) tries to extract a suggested filename from the url. This regular expression hangs depending on the dataurl.

Solution is to specify a name in the datauri string, so that an accepted name is always found, as mentioned in comment 1 of Is there any way to specify a suggested filename when using data: URI?

function open_data_uri_window(url) {
   var url_with_name = url.replace("data:application/pdf;", "data:application/pdf;name=myname.pdf;")
   var html = '<html>' +
    '<style>html, body { padding: 0; margin: 0; } iframe { width: 100%; height: 100%; border: 0;}  </style>' +
    '<body>' +
    '<p>new viewer</p>' +
    '<iframe type="application/pdf" src="' + url_with_name + '"></iframe>' +
    '</body></html>';
    var a = window.open("about:blank", "Zupfnoter");
    a.document.write(html);
    a.document.close();
}

Hint: The specified name is not respected by Chrome's builtin viewer

这篇关于当通过数据网址显示PDF时,Firefox挂起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 13:10