我有一个自动生成的PDF文件,我需要在HTML中显示该PDF文件。我的问题是:如何在HTML中使用PDF .js显示本地PDF文件?PDF文件是否应该按照某些标准生成?
当前回答
便携式文件格式(PDF)。
Any Browser « Use _Embeddable Google Document Viewer to embed the PDF file in iframe. <iframe src="http://docs.google.com/gview? url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"> </iframe> Only for chrome browser « Chrome PDF viewer using plugin. pluginspage=http://www.adobe.com/products/acrobat/readstep2.html. <embed type="application/pdf" src="http://www.oracle.com/events/global/en/java-outreach/resources/java-a-beginners-guide-1720064.pdf" width="100%" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html" background-color="0xFF525659" top-toolbar-height="56" full-frame="" internalinstanceid="21" title="CHROME">
示例小片:
<html> <head></head> <body style=" height: 100%;"> <div style=" position: relative;"> <div style="width: 100%; /*overflow: auto;*/ position: relative;height: auto; margin-top: 70px;"> <p>An <a href="https://en.wikipedia.org/wiki/Image_file_formats" >image</a> is an artifact that depicts visual perception </p> <!-- To make div with scroll data [max-height: 500;]--> <div style="/* overflow: scroll; */ max-height: 500; float: left; width: 49%; height: 100%; "> <img width="" height="400" src="https://peach.blender.org/wp-content/uploads/poster_bunny_bunnysize.jpg?x11217" title="Google" style="-webkit-user-select: none;background-position: 0px 0px, 10px 10px;background-size: 20px 20px;background-image:linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee 100%),linear-gradient(45deg, #eee 25%, white 25%, white 75%, #eee 75%, #eee 100%);cursor: zoom-in;" /> <p>Streaming an Image form Response Stream (binary data) « This buffers the output in smaller chunks of data rather than sending the entire image as a single block. <a href="http://www.chestysoft.com/imagefile/streaming.asp" >StreamToBrowser</a> </p> </div> <div style="float: left; width: 10%; background-color: red;"></div> <div style="float: left;width: 49%; "> <img width="" height="400" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot"/> <p>Streaming an Image form Base64 String « embedding images directly into your HTML. <a href="https://en.wikipedia.org/wiki/Data_URI_scheme"> <sup>Data URI scheme</sup> </a> <a href="https://codebeautify.org/image-to-base64-converter"> <sup>, Convert Your Image to Base64</sup> </a> <pre>data:[<media type>][;base64],<data></pre> </p> </div> </div> <div style="width: 100%;overflow: auto;position: relative;height: auto; margin-top: 70px;"> <video style="height: 500px;width: 100%;" name="media" controls="controls"> <!-- autoplay --> <source src="http://download.blender.org/peach/trailer/trailer_400p.ogg" type="video/mp4"> <source src="http://download.blender.org/peach/trailer/trailer_400p.ogg" type="video/ogg"> </video> <p>Video courtesy of <a href="https://www.bigbuckbunny.org/" >Big Buck Bunny</a>. </p> <div> <div style="width: 100%;overflow: auto;position: relative;height: auto; margin-top: 70px;"> <p>Portable Document Format <a href="https://acrobat.adobe.com/us/en/acrobat/about-adobe-pdf.html?promoid=CW7625ZK&mv=other" >(PDF)</a>. </p> <div style="float: left;width: 49%; overflow: auto;position: relative;height: auto;"> <embed type="application/pdf" src="http://www.oracle.com/events/global/en/java-outreach/resources/java-a-beginners-guide-1720064.pdf" width="100%" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html" background-color="0xFF525659" top-toolbar-height="56" full-frame="" internalinstanceid="21" title="CHROME"> <p>Chrome PDF viewer <a href="https://productforums.google.com/forum/#!topic/chrome/MP_1qzVgemo"> <sup>extension</sup> </a> <a href="https://chrome.google.com/webstore/detail/surfingkeys/gfbliohnnapiefjpjlpjnehglfpaknnc"> <sup> (surfingkeys)</sup> </a> </p> </div> <div style="float: left; width: 10%; background-color: red;"></div> <div style="float: left;width: 49%; "> <iframe src="https://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true#:page.7" style="" width="100%" height="500px" allowfullscreen="" webkitallowfullscreen=""></iframe> <p>Embeddable <a href="https://googlesystem.blogspot.in/2009/09/embeddable-google-document-viewer.html" >Google</a> Document Viewer. Here's the code I used to embed the PDF file: <pre> <iframe src="http://docs.google.com/gview? url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe> </pre> </p> </div> </div> </div> </body> </html>
其他回答
我以前有过类似的东西,通常使用标签
<a href="path_of_your_pdf/your_pdf_file.pdf" tabindex="-1"><strong>click here</strong></a>
但是像上面提到的,找到一些其他的方法是很有趣的!
这个方法也很有用:
在桌面和移动浏览器上显示pdf文件:
<object data="./filename.pdf" type="application/pdf" width="500px" height="600px"> <p>你的浏览器没有PDF插件。 <a href="./filename.pdf">点击这里下载PDF文件</a></p> . PDF < /对象>
便携式文件格式(PDF)。
Any Browser « Use _Embeddable Google Document Viewer to embed the PDF file in iframe. <iframe src="http://docs.google.com/gview? url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"> </iframe> Only for chrome browser « Chrome PDF viewer using plugin. pluginspage=http://www.adobe.com/products/acrobat/readstep2.html. <embed type="application/pdf" src="http://www.oracle.com/events/global/en/java-outreach/resources/java-a-beginners-guide-1720064.pdf" width="100%" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html" background-color="0xFF525659" top-toolbar-height="56" full-frame="" internalinstanceid="21" title="CHROME">
示例小片:
<html> <head></head> <body style=" height: 100%;"> <div style=" position: relative;"> <div style="width: 100%; /*overflow: auto;*/ position: relative;height: auto; margin-top: 70px;"> <p>An <a href="https://en.wikipedia.org/wiki/Image_file_formats" >image</a> is an artifact that depicts visual perception </p> <!-- To make div with scroll data [max-height: 500;]--> <div style="/* overflow: scroll; */ max-height: 500; float: left; width: 49%; height: 100%; "> <img width="" height="400" src="https://peach.blender.org/wp-content/uploads/poster_bunny_bunnysize.jpg?x11217" title="Google" style="-webkit-user-select: none;background-position: 0px 0px, 10px 10px;background-size: 20px 20px;background-image:linear-gradient(45deg, #eee 25%, transparent 25%, transparent 75%, #eee 75%, #eee 100%),linear-gradient(45deg, #eee 25%, white 25%, white 75%, #eee 75%, #eee 100%);cursor: zoom-in;" /> <p>Streaming an Image form Response Stream (binary data) « This buffers the output in smaller chunks of data rather than sending the entire image as a single block. <a href="http://www.chestysoft.com/imagefile/streaming.asp" >StreamToBrowser</a> </p> </div> <div style="float: left; width: 10%; background-color: red;"></div> <div style="float: left;width: 49%; "> <img width="" height="400" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg==" alt="Red dot"/> <p>Streaming an Image form Base64 String « embedding images directly into your HTML. <a href="https://en.wikipedia.org/wiki/Data_URI_scheme"> <sup>Data URI scheme</sup> </a> <a href="https://codebeautify.org/image-to-base64-converter"> <sup>, Convert Your Image to Base64</sup> </a> <pre>data:[<media type>][;base64],<data></pre> </p> </div> </div> <div style="width: 100%;overflow: auto;position: relative;height: auto; margin-top: 70px;"> <video style="height: 500px;width: 100%;" name="media" controls="controls"> <!-- autoplay --> <source src="http://download.blender.org/peach/trailer/trailer_400p.ogg" type="video/mp4"> <source src="http://download.blender.org/peach/trailer/trailer_400p.ogg" type="video/ogg"> </video> <p>Video courtesy of <a href="https://www.bigbuckbunny.org/" >Big Buck Bunny</a>. </p> <div> <div style="width: 100%;overflow: auto;position: relative;height: auto; margin-top: 70px;"> <p>Portable Document Format <a href="https://acrobat.adobe.com/us/en/acrobat/about-adobe-pdf.html?promoid=CW7625ZK&mv=other" >(PDF)</a>. </p> <div style="float: left;width: 49%; overflow: auto;position: relative;height: auto;"> <embed type="application/pdf" src="http://www.oracle.com/events/global/en/java-outreach/resources/java-a-beginners-guide-1720064.pdf" width="100%" height="500" alt="pdf" pluginspage="http://www.adobe.com/products/acrobat/readstep2.html" background-color="0xFF525659" top-toolbar-height="56" full-frame="" internalinstanceid="21" title="CHROME"> <p>Chrome PDF viewer <a href="https://productforums.google.com/forum/#!topic/chrome/MP_1qzVgemo"> <sup>extension</sup> </a> <a href="https://chrome.google.com/webstore/detail/surfingkeys/gfbliohnnapiefjpjlpjnehglfpaknnc"> <sup> (surfingkeys)</sup> </a> </p> </div> <div style="float: left; width: 10%; background-color: red;"></div> <div style="float: left;width: 49%; "> <iframe src="https://docs.google.com/gview?url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true#:page.7" style="" width="100%" height="500px" allowfullscreen="" webkitallowfullscreen=""></iframe> <p>Embeddable <a href="https://googlesystem.blogspot.in/2009/09/embeddable-google-document-viewer.html" >Google</a> Document Viewer. Here's the code I used to embed the PDF file: <pre> <iframe src="http://docs.google.com/gview? url=http://infolab.stanford.edu/pub/papers/google.pdf&embedded=true" style="width:600px; height:500px;" frameborder="0"></iframe> </pre> </p> </div> </div> </div> </body> </html>
如果你想使用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网页中实现PDF文件非常简单。
<embed src="file_name.pdf" width="800px" height="2100px" />
确保根据你的需要改变宽度和高度。