我有一个自动生成的PDF文件,我需要在HTML中显示该PDF文件。我的问题是:如何在HTML中使用PDF .js显示本地PDF文件?PDF文件是否应该按照某些标准生成?


当前回答

如果你想使用pdf.js,我建议你阅读这个

你也可以把你的pdf文件上传到某个地方(比如谷歌Drive),并在iframe中使用它的URL

or

<object data="data/test.pdf" type="application/pdf" width="300" height="200">
<a href="data/test.pdf">test.pdf</a>
</object>

其他回答

在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>

我使用谷歌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显示,但你也可以通过指出路径使用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 );
?>

在HTML网页中实现PDF文件非常简单。

<embed src="file_name.pdf" width="800px" height="2100px" />

确保根据你的需要改变宽度和高度。

你可以使用

<iframe src="your_pdf_file_path" height="100%" width="100%" scrolling="auto"></iframe>

或者,如果你想让它占据整页:

<a href="your_pdf_file_path">Link</a>