我有一个自动生成的PDF文件,我需要在HTML中显示该PDF文件。我的问题是:如何在HTML中使用PDF .js显示本地PDF文件?PDF文件是否应该按照某些标准生成?
当前回答
在HTML网页中实现PDF文件非常简单。
<embed src="file_name.pdf" width="800px" height="2100px" />
确保根据你的需要改变宽度和高度。
其他回答
我知道你想使用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 );
?>
gofilord提供的答案是正确的,但我也可能会补充说,如果你创建一个空桶,将你的pdf倒入,你应该给它一个src=""像…
<embed id="fooEmbed" src="">
...在HTML和javascript…
document.getElementById('fooEmbed').src = 'bar.pdf';
...它会起作用的。如果你这样做…
<embed id="fooEmbed">
...这是行不通的。
在HTML网页中实现PDF文件非常简单。
<embed src="file_name.pdf" width="800px" height="2100px" />
确保根据你的需要改变宽度和高度。
我使用谷歌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>
你可以使用
<iframe src="your_pdf_file_path" height="100%" width="100%" scrolling="auto"></iframe>
或者,如果你想让它占据整页:
<a href="your_pdf_file_path">Link</a>