我有一个自动生成的PDF文件,我需要在HTML中显示该PDF文件。我的问题是:如何在HTML中使用PDF .js显示本地PDF文件?PDF文件是否应该按照某些标准生成?
当前回答
我知道你想使用HTMl显示,但你也可以通过指出路径使用php打开PDF文件,浏览器将在几个简单的步骤中呈现它
<?php
$your_file_name = "url_here";
//Content type and this case its a PDF
header("Content-type: application/pdf");
header("Content-Length: " . filesize($your_file_name ));
//Display the file
readfile($your_file_name );
?>
其他回答
最简单的方法是,
<iframe src="pdf-link">
</iframe>
如果它仍然下载而不是查看,检查服务器响应头,它应该有,Content-Disposition:内联,而不是,Content-Disposition:附件。
我知道你想使用HTMl显示,但你也可以通过指出路径使用php打开PDF文件,浏览器将在几个简单的步骤中呈现它
<?php
$your_file_name = "url_here";
//Content type and this case its a PDF
header("Content-type: application/pdf");
header("Content-Length: " . filesize($your_file_name ));
//Display the file
readfile($your_file_name );
?>
我以前有过类似的东西,通常使用标签
<a href="path_of_your_pdf/your_pdf_file.pdf" tabindex="-1"><strong>click here</strong></a>
但是像上面提到的,找到一些其他的方法是很有趣的!
我使用谷歌Docs嵌入式PDF查看器。这些文档不必上传到谷歌docs,但必须在网上可用。
<iframe src="https://docs.google.com/gview?url=https://path.com/to/your/pdf.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe>
在html页面的pc很容易实现
<embed src="study/sample.pdf" type="application/pdf" height="300px" width="100%">
但PDF显示在移动的这段代码是不可能的,你必须需要一个插件
如果你没有响应你的网站。然后上面的代码pdf不显示在手机上,但你可以把下载选项后的代码
<embed src="study/sample.pdf" type="application/pdf" height="300px" width="100%" class="responsive">
<a href="study/sample.pdf">download</a>