简体   繁体   English

Chrome中的文件大小问题,用于OBJECT标记中的base64编码的PDF数据

[英]File size issue in Chrome for base64-encoded PDF data in OBJECT tag

My problem is related to displaying base64-encoded PDF file data in Chrome browser. 我的问题与在Chrome浏览器中显示base64编码的PDF文件数据有关。 The PDF files are not static physical files rather they are streams converted to base64-encoded data. PDF文件不是静态物理文件,而是转换为base64编码数据的流。 It is a single page application using Node.js backend. 它是使用Node.js后端的单页面应用程序。 The pdf file is displayed in a modal popup box, instead of a new tab or window. pdf文件显示在模式弹出框中,而不是新的选项卡或窗口。 The code responsible for displaying the base64-encoded PDF data is given below: 负责显示base64编码的PDF数据的代码如下:

var objbuilder = '';
objbuilder += ('<object width="100%" height="100%" data="data:application/pdf;base64,');
objbuilder += (r.response);
objbuilder += ('" type="application/pdf" class="internal">');
objbuilder += ('</object>');
var html = '';
html += '<div class="modal fade in" id="linkedDoc" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">';
html += '<div class="modal-dialog">';
html += '<div class="modal-content" style="height:800px;width:600px;">';
html += '<div class="modal-body" style="height: 100%;" id = "linkedBody">';
html += '<div style="height:25px;clear:both;display:block;">';
html += '<a class="controls previous" href="javascript:void(0);" data-dismiss="modal" aria-hidden="true">Close</a>';
html += '</div></div></div></div></div>';
$('#linkedDoc').remove();
$('body').append(html);
$('#linkedBody').append(objbuilder);
$('.modal').modal({
    keyboard: false,
    show: true
});
$('.modal-dialog').draggable({
    handle: ".modal-header"
});
$('.modal-content').resizable();
$('#linkedBody').on('show.bs.modal', function () {
    $(this).find('.modal-body').css({
        'max-height': '100%',
        'max-width': '100%'
    });
});

The approach works well for file with almost 1 MB file size but not more than that. 该方法适用于文件大小近1 MB但不超过该文件的文件。 Some of the files I want to display are 5 MBs and some are even 10 MBs. 我想要显示的一些文件是5 MB,有些甚至是10 MB。 How can I fix this issue. 我该如何解决这个问题。 This and This SO questions are relevant to the topic but not specific for my situation. 这个这个 SO问题与主题相关,但不是我的具体情况。

I can't use HTML 'embed' and 'iframe' tags because they need a physical file as their 'src' attribute but I don't have a physical PDF file rather its in-memory data. 我不能使用HTML'embed'和'iframe'标签,因为它们需要一个物理文件作为'src'属性,但我没有物理PDF文件而是内存数据。

Anyone stumbling upon this question in future, I fixed it using blob:URL technique. 今后有人绊倒这个问题,我用blob:URL技术修复了它。 THIS StackOverflow question guided me towards the solution. 这个 StackOverflow问题引导我走向解决方案。 So instead of opening the PDF file in HTML object element, I opened it in a new window using Blob URL. 因此,我不是在HTML对象元素中打开PDF文件,而是使用Blob URL在新窗口中打开它。 It could not be achieved using data:URL after Chrome version 60 update in which they blocked data URLs. 使用数据无法实现:Chrome版本60更新后的网址阻止了数据网址。

First Approach 第一种方法

Can you try with iframe tag instead of object tag. 您可以尝试使用iframe标记而不是对象标记。

Second Approach 第二种方法

can you provide the link for PDF instead of actual data. 你能提供PDF而不是实际数据的链接吗?

you can create the pdf file and store in some where then after provide the link to object tag. 您可以创建pdf文件并存储在某些位置后提供对象标记的链接。

Third You can try Embed tag also 第三,您也可以尝试使用Embed标签

May be Solve your issue :) 可能解决你的问题:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM