Php 使用dataurl将PDF流式传输到iframe-仅适用于Chrome
以下内容适用于Chrome,但iframe内容在Firefox15和IE9中是空白的Php 使用dataurl将PDF流式传输到iframe-仅适用于Chrome,php,html,iframe,data-url,Php,Html,Iframe,Data Url,以下内容适用于Chrome,但iframe内容在Firefox15和IE9中是空白的 <html> <head></head> <body> <p>this n that</p> <iframe type="application/pdf" width="95%" height="95%" src="data:applica
<html>
<head></head>
<body>
<p>this n that</p>
<iframe type="application/pdf"
width="95%"
height="95%"
src="data:application/pdf;base64,<?php echo base64_encode(file_get_contents('memlist.pdf'));?>">
Oops, you have no support for iframes.
</iframe>
<p>this n that</p>
</body>
</html>
问题似乎在于数据URL。如果我把它改为src=memlist.pdf,那么它在任何地方都可以工作。PDF大小为75kb
DataURL是否存在某些当前浏览器限制
我试图避免使用http url调用服务器,因为一些身份验证问题我刚刚逐字复制了您的源代码,将php输出编码pdf的部分替换为我从在线编码器返回的字符串 原始pdf为141kb,编码字符串为194065字节,相当于url 它在Chrome中工作得很好,就像它为您所做的一样。同样,歌剧也不会有一个酒吧 因此,我从iframe标记中删除了type='application/pdf'属性。现在Chrome和Opera都将显示该文件,而IE9仍然拒绝 我试图通过javascript更改src以防万一,通过Opera/Chrome没有问题,但仍然无法使用IE 在过去,我使用php动态创建PDF,只需将iframe的src设置为php文件的url,并使用GET参数完成。这在IE6和opera、chrome和ff上运行得很好——从未在移动设备上尝试过,这是5年前的事了 我希望一些旧的示例代码会有所帮助: 1个Javascript来插入iframe fpdf的输出部分
我刚刚逐字复制了您的源代码,将php输出编码pdf的部分替换为我从在线编码器返回的字符串 原始pdf为141kb,编码字符串为194065字节,相当于url 它在Chrome中工作得很好,就像它为您所做的一样。同样,歌剧也不会有一个酒吧 因此,我从iframe标记中删除了type='application/pdf'属性。现在Chrome和Opera都将显示该文件,而IE9仍然拒绝 我试图通过javascript更改src以防万一,通过Opera/Chrome没有问题,但仍然无法使用IE 在过去,我使用php动态创建PDF,只需将iframe的src设置为php文件的url,并使用GET参数完成。这在IE6和opera、chrome和ff上运行得很好——从未在移动设备上尝试过,这是5年前的事了 我希望一些旧的示例代码会有所帮助: 1个Javascript来插入iframe fpdf的输出部分
function showPdfTt(studentId)
{
var url, tgt;
title = byId("popupTitle");
title.innerHTML = "Timetable for " + studentId;
tgt = byId("popupContent");
url = "pdftimetable.php?";
url += "id="+studentId;
url += "&type=Student";
tgt.innerHTML = "<iframe onload=\"centerElem(byId('box'))\" src='"+url+"' width=\"700px\" height=\"500px\"></iframe>";
}
$pdfStr = $pdf->output();
$myFile = fopen("lastRequested.pdf", "wb"); // just here for debugging purposes
fwrite($myFile, $pdfStr);
fclose($myFile);
$pdf->ezStream(); // send output to stdout (the browser) - uses fpdf for generation
exit;
if(php_sapi_name()!='cli')
{
//We send to a browser
header('Content-Type: application/pdf');
if(headers_sent())
$this->Error('Some data has already been output, can\'t send PDF file');
header('Content-Length: '.strlen($this->buffer));
header('Content-Disposition: inline; filename="'.$name.'"');
header('Cache-Control: private, max-age=0, must-revalidate');
header('Pragma: public');
ini_set('zlib.output_compression','0');
}
echo $this->buffer;
break;